Solved

How to deploy a Servlet on TomCat?

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 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