How to execute java servlet using tomcat server?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shivapadma
    New Member
    • Mar 2007
    • 40

    #1

    How to execute java servlet using tomcat server?

    1.I installed apache tomcat.


    2.I have the following java servlet

    import java.io.*;
    import javax.sevlet.*;
    import javax.servlet.h ttp.*;
    public class ser extends HttpServlet
    {
    public void doGet(HttpServl etRequest req,HttpServlet Response res) throws ServletExceptio n,IOException
    {
    res.setContentT ype("text.html" );
    PrintWriter out=res.getWrit er();

    String name=req.getPar ameter("name");
    out.println("<h tml>");
    out.println("<b ody>");
    out.println("he llo"+name);
    out.println("</body>></html>");
    }

    }


    3.where should i put this servlet in tomcat.

    4.I want clear explanation for executing javaservet using tomcat server.


    please,kindly give reply for this problem.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by shivapadma
    1.I installed apache tomcat.


    2.I have the following java servlet

    import java.io.*;
    import javax.sevlet.*;
    import javax.servlet.h ttp.*;
    public class ser extends HttpServlet
    {
    public void doGet(HttpServl etRequest req,HttpServlet Response res) throws ServletExceptio n,IOException
    {
    res.setContentT ype("text.html" );
    PrintWriter out=res.getWrit er();

    String name=req.getPar ameter("name");
    out.println("<h tml>");
    out.println("<b ody>");
    out.println("he llo"+name);
    out.println("</body>></html>");
    }

    }


    3.where should i put this servlet in tomcat.

    4.I want clear explanation for executing javaservet using tomcat server.


    please,kindly give reply for this problem.
    ... and what does the documentation say?

    Comment

    • shivapadma
      New Member
      • Mar 2007
      • 40

      #3
      Originally posted by r035198x
      ... and what does the documentation say?

      I have compiled the file and placed in

      C:\Program Files\Apache Software Foundation\Tomc at 5.5\webapps\ROO T\WEB-INF\classes\


      and

      i opened the browser and gave the url as
      http://localhost:8080/servlet/ser


      but
      i am getting an error called

      /servlet/ser does not found.

      what should i do for running the servlet.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by shivapadma
        what should i do for running the servlet.
        This bluntly shows that you haven't read all of the documentation. The docs also
        talk about a deployment decriptor (a bit of xml) which you have to create.

        kind regards,

        Jos

        Comment

        • pronerd
          Recognized Expert Contributor
          • Nov 2006
          • 392

          #5
          Originally posted by shivapadma
          /servlet/ser does not found.
          what should i do for running the servlet.
          You need to define the Servlet in deployment descriptor (web.xml) in the WEB-INF folder. If you are using an IDE like Netbeans or Eclipse you may want to look at having them create a WAR file to deploy to Tomcat.


          This web.xml would let you call http://localhost:8080/myServlet
          [HTML]
          <?xml version="1.0"?>

          <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
          xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocat ion="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
          version="2.4">

          <servlet>
          <servlet-name>myServlet</servlet-name>
          <servlet-class><<Your Class Name Here>></servlet-class>
          </servlet>

          <servlet-mapping>
          <servlet-name>myServlet</servlet-name>
          <url-pattern>myServl et</url-pattern>
          </servlet-mapping>

          <welcome-file-list>
          <welcome-file>index.html </welcome-file>
          </welcome-file-list>

          </web-app>
          [/HTML]

          Comment

          Working...