The getQueryString() method is defined in the HttpServletRequest interface, which is used to retrieve the query string of the HTTP request. A query string is the string on the URL to the right of the path to the servlet. Using this a programmer can know the data which is sent from the client(when a form is submitted) [Read more…]
Servlet Interface provides the common methods which needs to be implemented by all the servlets. All the servlets must implement this interface directly or indirectly. To have the implementation of the Servlet Interface you can extend GenericServlet Class(javax.servlet.GenericServlet) or HttpServlet Class (javax.servlet.http.HttpServlet). Read through Running Your First Servlet Application article for the basic understanding. [Read more…]
Once we have installed and configured Tomcat, we need to follow the below five steps to run our First Hello World Application.
- Create a directory under Tomcat for our application.
- Coding our servlet. We will be using javax.servlet package and the javax.servlet.http package in our source code.
- Create a deployment descriptor.
- Compile our source code.
- Run Tomcat and call the servlet from the web browser.
The Servlet Container is responsible for maintaining the life cycle of a Servlet. The life cycle has the below following phases.
- Load Servlet Class
- Servlet instance is created
- init() method is invoked
- service() method is invoked
- destroy() method is invoked
ServletConfig and ServletContext are the two import interfaces in ServletAPI, Lets see whats the difference between them and how to use.
- ServletConfig is available in the javax.servlet.* package.
- ServletConfig object will be created during the initialization(init()) of the servlet.