aspose file tools*
The moose likes Servlets and the fly likes Unable to run servlet on my machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Unable to run servlet on my machine" Watch "Unable to run servlet on my machine" New topic
Author

Unable to run servlet on my machine

Jigeshs Shahs
Greenhorn

Joined: May 28, 2009
Posts: 26
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>");

}
}


William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
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


Java Resources at www.wbrogden.com
Jigeshs Shahs
Greenhorn

Joined: May 28, 2009
Posts: 26
i didnt got what you were trying to tell can you elaborate more on it....
and whas is the solution for this
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

Read this.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jigeshs Shahs
Greenhorn

Joined: May 28, 2009
Posts: 26
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...
Jhakda Velu
Ranch Hand

Joined: Feb 26, 2008
Posts: 166
How have you "packaged" your servlet? Did you change your web.xml ?
Jhakda


If I become filthy rich, I'll sponsor research for painless dental treatment at Harvard Medical School. Thats why,I'm learning Java.I have 32 teeth, 22 are man made.
Jigeshs Shahs
Greenhorn

Joined: May 28, 2009
Posts: 26
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
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
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

Joined: May 28, 2009
Posts: 26
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
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to run servlet on my machine
 
Similar Threads
Unable to execute Servlet
404 Error
Cannot get Servlets Demystified Problem
new to tomcat
HTTP Status 404 - /ch1/Serv1/