Solved

How to deploy a Servlet on TomCat?

Posted on 2003-11-06
3
1,548 Views
Last Modified: 2008-02-01
Hi
I am new to tomcat web server.

I just wrote a helloworld  servlet and then wrote a .html document to embed the class file.
I dropped the .html file in the d:\tomcat 4.1\webapps\examples\servlets directory.

Then I dropped the class file in the d:\tomcat 4.1\webapps\examples\WEB-INF\classes directory

Then I opened a brower and typed
http://localhost:8080/examples/servlets/MyHelloWorld.html

Ok the html script started. But the class file was not executed as I cannot see the result of that
coming out.

What did I do wrong?

PS. Web Server is running fine. I have a shell showing that.

Here is are my code....

<!-- MyHelloWorld.html -->
<HTML>  
  <HEAD>
     <TITLE>
        Servlet HTTP GET Example
     </TITLE>
     </HEAD>
          <BODY>        
                <FORM          
                  ACTION=http://localhost:8080/webapps/examples/WEB-INF/classes/MyHelloWorld
                  METHOD=<"GET">
                 <P> Click the button to have the servlet send an HTML document</P>
                             <INPUT TYPE="submit" VALUE="Get HTML Document">
               </FORM>
          </BODY>
</HTML>


and the servlet class is....
import java.io.*;
      import javax.servlet.http.*;

      public class MyHelloWorld extends HttpServlet
      {

          public void doGet(HttpServletRequest request,
                     HttpServletResponse response)
                                  throws IOException
           {
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          out.println("<html>");
          out.println("<body>");
          out.println("<head>");
          out.println("<title>Hello World, I Just Started Servlets!</title>");
          out.println("</head>");
          out.println("<body>");
          out.println("<h1>Hello World,  I Just Started Servlets!</h1>");
          out.println("</body>");
          out.println("</html>");
         }
       }

0
Comment
Question by:prain
3 Comments
 
LVL 1

Accepted Solution

by:
robsmart earned 50 total points
ID: 9701522
You'll have to edit the web.xml file in \examples\WEB_INF\ to add an entry for your servlet

 <servlet>
        <servlet-name>
            MyHelloWorld
        </servlet-name>
        <servlet-class>
            MyHelloWorld
        </servlet-class>

    </servlet>

    <servlet-mapping>
        <servlet-name>
          MyHelloWorld
        </servlet-name>
        <url-pattern>
            /MyHelloWorld
        </url-pattern>
    </servlet-mapping>


also in your HTML change the form submitaction to

ACTION=http://localhost:8080/webapps/examples/MyHelloWorld

you dont actually need an html page to call the servlet youcan just put the url http://localhost:8080/webapps/examples/MyHelloWorld
in your browser
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MDB2 Error: not found 4 200
Enabling compression in WARP Framework template 5 92
Increase size of permitted URI 4 54
Why Xampp showing MySQL as Maria DB on Welcome Page ? 8 89
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question