Solved

How to deploy a Servlet on TomCat?

Posted on 2003-11-06
3
1,539 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
Comment Utility
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now