This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes problem in execution Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Reply 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: 503

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..


Regards, Prasad
SCJP 5 (93%)
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: 503

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: 56150
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 56150
    
  13

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: 12265
    
    1
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

Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: problem in execution
 
Similar Threads
Servlets..
my first servlet please help.
HelloServlet not running ?
Beginner's, servlet problem
tomcat- set JAVA_HOME point to jdk..