• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

problem in execution

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't tell, Show us..
Can you post your code here? Also, web.xml..
 
Sheriff
Posts: 67553
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
c shah
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67553
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic