• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Unable to run servlet on my machine

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am unable to run servlet on my machine
its giving error message as Http Status 404 :description The requested resource () is not available.

D:\Apache Software Foundation\Tomcat 5.5\webapps\ch1-->is directory

web .xml is placed in D:\Apache Software Foundation\Tomcat 5.5\webapps\ch1\WEB-INF

ch1servlet.class is placed in D:\Apache Software Foundation\Tomcat 5.5\webapps\ch1\WEB-INF\classes

In Internet Explorer 6.0 address bar the command i have wriiten is http://localhost:8080/ch1/Serv1

I am using tomcat server 5.5 after starting the server also it is giving the same error message

New to the Servlet world...please help me

Web.xml is as follow as

<?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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>

<!-- JSPC servlet mappings start -->

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

<!-- JSPC servlet mappings end -->

</web-app>


Source file ch1servlet.java is as follow as

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>Chapter1 Servlet </h1>"+ "<br>"+today+"</body>"+"</html>");

}
}


 
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
Here is your problem:



ALL classes used in servlets should be in a package and stored according to the package under classes.

The reason is that without a package ("default package") the JVM looks in the "current" directory. With servlets you have no control over the current directory, the container cant find the class so you get that error message.

This is one of the most common problems for people new to servlets.

Bill

 
Jigeshs Shahs
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i didnt got what you were trying to tell can you elaborate more on it....
and whas is the solution for this
 
Sheriff
Posts: 67620
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
Read this.
 
Jigeshs Shahs
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have packaged my class
but it is giving the same error that The requested resource () is not available.
what else should I do now...
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How have you "packaged" your servlet? Did you change your web.xml ?
Jhakda
 
Jigeshs Shahs
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i did change web.xml file but Still its not working.
One problem I have is thats whenever I try 2 run even a simple Html file say Helloworld.html from
D:\Apache Software Foundation\Tomcat 5.5\webapps\ch1 using the link as http://localhost:8080/ch1/helloworld.html it gives errror as The request resource is not available.
but when i run the same file from D:\Apache Software Foundation\Tomcat 5.5\webapps\root with link as http://localhost:8080/helloworld.html it displays the page properly.
really cant figure out wat is the problem
 
William Brogden
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

D:\Apache Software Foundation\Tomcat 5.5\webapps\ch1 using the link as http://localhost:8080/ch1/helloworld.html it gives errror as The request resource is not available.



The reason is probably that Tomcat is not recognizing ch1 as a valid web application. Usually this is the result of a faulty directory structure or a faulty web.xml deployment descriptor. Error messages should be showing up in the log files.

You are stopping and restarting Tomcat after every change, right?

Bill
 
Jigeshs Shahs
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I am stopping and restarting Tomcat after every change
but what is the solution for this problem

 
William Brogden
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
The solution is to find out why Tomcat is not accepting ch1 as a valid web application.

Very common reasons you should check:

1. web.xml not valid xml format, gets rejected during startup.
2. directory structure under classes does not follow package structure, class not found, servlet not created
3. URL being used does not map to servlet according to web.xml rules. Remember, case is important.

Both 1&2 should result in error messages
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic