aspose file tools*
The moose likes Servlets and the fly likes problem in execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem in execution" Watch "problem in execution" New topic
Author

problem in execution

c shah
Greenhorn

Joined: May 12, 2011
Posts: 10
i am preparing for scwcd.I was trying the first servlet example.I made a java file Ch1Servlet.java and DD web.xml.I performed all the steps written in the book.
project1 and tomcat both are in d directory.I compiled the program using command
javac \apache-tomcat-5.5.33\tomcat\common\lib\servlet-api.jar -d classes src/Ch1Servlet.java.then i copied the class file to web-inf/classes and xml file to web-inf.
i did everything perfectly but when i type http://localhost:8080/ch1/Serv1 Http status 404 error is coming.it says requested resource is not available.
Tomcat is running perfectly.when i point my browser to localhost:8080 home page of apahce is coming.
what could be the probelm?It is getting very frustrating.please help me.
BIG BIG Thanks in advance



Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 532

You can show us your code here.. one question, did you map your servlet in web.xml?

P:S: Writing classes inside default package is discouraged, can you put your servlet class in some package..
c shah
Greenhorn

Joined: May 12, 2011
Posts: 10
I did not put my servlet in any package as it was the very first example in the book and.it was not put in any package.I did map my servlet in web.xml
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 532

Don't tell, Show us..
Can you post your code here? Also, web.xml..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61233
    
  66

Put your servlet in a package. The book is likely old, and not putting the servlet in a package is unlikely to work any longer.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
c shah
Greenhorn

Joined: May 12, 2011
Posts: 10
This is web.xml file whose path is project/etc/web.xml

<?xml version="1.0" encoding="ISO-8851-1" ?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>

This is Ch1Servlet.java whose path is project/src/Ch1Servlet.java


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

public class Ch1Servlet extends HttpServlet

{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException
{
PrintWriter out=response.getWriter();
java.util.Date today=new java.util.Date();
out.println("<html>" +
"<body>" +
"<h1 align=center>please god help me</h1>"
+ "<br>" + today + "</body>" + "</html>");
}
}

As i said i compiled the java file and put the .class file in project/classes
Then i copied web.xml in web-inf and .class file in classes.
Tomcat is running perfectly but when i type localhost:8080/ch1/Serv1 it says
Http Status 404
type status report
message
description The requested resource () is not available.
Apache tomcat /5.5.33
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61233
    
  66

I repeat:
Bear Bibeault wrote:Put your servlet in a package. The book is likely old, and not putting the servlet in a package is unlikely to work any longer.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
Early editions of Tomcat had a servlet called the Invoker servlet which gave limited execution capabilities to servlets not in packages. I suppose the idea was to make it easy for beginners to execute a first servlet.

This idea turned out to be a disaster which has caused endless trouble ever since. Just accept the annoyance of learning how to use web.xml and packages - you will be glad you did.

Bill
 
wood burning stoves
 
subject: problem in execution