aspose file tools*
The moose likes Servlets and the fly likes servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet" Watch "servlet" New topic
Author

servlet

subhala subramanian
Greenhorn

Joined: Jan 31, 2010
Posts: 10
how to run a servlet in tomcat server
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Examples here -> http://java.sun.com/javaee/5/docs/tutorial/doc/bnafd.html


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
subhala subramanian
Greenhorn

Joined: Jan 31, 2010
Posts: 10
hi sir,

while running a servlet ..im getting an error HTTP 404 resource not available

development directory

webapps
sample
hello.jsp
WEB-INF
web.xml
classes
HelloWorldExample.java

HelloWorldExample.java

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class HelloWorldExample extends HttpServlet {


public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<head>");

String title = rb.getString("helloworld.title");

out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("<a href=\"../helloworld.html\">");
out.println("<img src=\"../images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
out.println("<a href=\"../index.html\">");
out.println("<img src=\"../images/return.gif\" height=24 " +
"width=24 align=right border=0 alt=\"return\"></a>");
out.println("<h1>" + title + "</h1>");
out.println("</body>");
out.println("</html>");
}
}

web.xml


<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>HelloWorldExample</servlet-name>
<servlet-class>HelloWorldExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/servlet/HelloWorldExample</url-pattern>
</servlet-mapping>
</web-app>



Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Please post code inside the CODE tags. It is much easier to read that way

As for the 404, are you sure the app is deployed ? How did you confirm this ?

What is the URL with which you tried to access the servlet ?
subhala subramanian
Greenhorn

Joined: Jan 31, 2010
Posts: 10
http://localhost:8080/sample/hello.jsp
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

subhala subramanian wrote:http://localhost:8080/sample/hello.jsp


Is sample the name of your web application?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

You are invoking a jsp not the servlet
subhala subramanian
Greenhorn

Joined: Jan 31, 2010
Posts: 10
http://localhost:8080/servlet/HelloWorldExample

my classpath is C:\>set CLASSPATH=.;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "servlet" in a forum completely dedicated to questions on Servlets isn't very helpful.

Please go back and change your post to add a more meaningful subject by clicking the


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: servlet