Solved

How to deploy a Servlet on TomCat?

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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