I have a servlet. I'm new in java. But i need to run the servlet. It has two methods:
public void doGet (HttpServletRequest request,
                     HttpServletResponse response) {...}
and
public void doPost HttpServletRequest request,
                     HttpServletResponse response) {...}
What steps i need to do to run the servlet? (I have tomcat 7 installed, eclipse SE with tomcat plugin, netBeans)
HttpServlet and override the method doGet and doPost, write your business logic in thereConfigure  web.xml, something like :
  <servlet>
    <servlet-name>helloworld</servlet-name>
    <servlet-class>test.helloworld</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>helloworld</servlet-name>
    <url-pattern>/helloworld</url-pattern>
  </servlet-mapping>
Deploy your web project in the tomcat
localhost:8080/mywebapp/helloworld.do in the browser's address bar, mywebapp is your project nameIf you are lucky, you will see the result.
Internally call to doGet and doPost will reach like below,
Client ----------------------------> Container  
sends request               |
                            |
                Creates    HttpServletRequest   HttpServletResponse objects 
                            |
                            |                   
                Create Thread for that Servlet and pass above objects to it
                            |
                            |
                Thread Call the Service() method and decision is made to call doGet() or doPost()
                            |
                            |
                    doGet()/doPost() called
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With