| 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: 6588
|
|
|
Examples here -> http://java.sun.com/javaee/5/docs/tutorial/doc/bnafd.html
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
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: 6588
|
|
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: 8795
|
|
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, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
|
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: 56179
|
|
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
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: servlet
|
|
|