0

I am wondering how NetBeans handles my package that contains my class source code to be compiled as a servlet

For manual cases in which I only install Tomcat or any other webservers and have them work out with my servlet, I may need to access my jsp page as http://host/app/mypackage.myclassname/

But in case of netbeans, things become easier as it do all stuff underneath for me and I only need to call something like http://host/app/myclassname/

and it works. There is no need to use a dot to call my class from a specified package name. Awesome!

By the way, how is doGet, doPost functions are processed. They don't seem to be called anywhere in my code but they are called when I specify their class container name in my URL.

Thank you so much for any replies.

Anabella
  • 39
  • 6

1 Answers1

0

By the way, how is doGet, doPost functions are processed. They don't seem to be called anywhere in my code but they are called when I specify their class container name in my URL.

You can configure the Servlet to listen on a particular (certain) HTTP URL Pattern that can configure via web.xml or with annotation (JavaEE 6 spec).

When a servlet is requested, its doGet() or doPost() method will be called based upon the request method (GET or POST).

For instance, for POST request :

<form method="post" action="your_servlet_url">
  ...
  <input type="submit"/>
</form>

FAQ - How do servlets work? Instantiation, session variables and multithreading

Community
  • 1
  • 1
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186