• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

404 Error

 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the first example from hfs i am coding....am new to tomcat ...used WSAD all along..soo
someone plz guide me

created a servlet named Ch1Servlet as below:
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>HF Chapter1</h1>"+
"<br>+today+</body></html>");
}
}

created an xml file name web.xml as below:
<web-app xmls="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://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>

created the following directory tree under Tomcat directory
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ch1\WEB-INF\classes
| |
| |
web.xml Ch1Servlet.class
and another directory tree
f:\project1
|
|
src classes etc
| |
| |
Ch1Servlet web.xml
.java

when i type http://localhost:8080/ch1/Serv1 in browser i get the error message as:

HTTP Status 404 - /ch1/Serv1

--------------------------------------------------------------------------------

type Status report

message /ch1/Serv1

description The requested resource (/ch1/Serv1) is not available.


--------------------------------------------------------------------------------
Apache Tomcat/4.1.30

can any1 plz explain the silly mistake i did here....
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pallavi,

I'd think you'd need to set the content type to the response, prior to getting a PrintWriter.



Also, is your deployment descriptor (DD) directly under the WEB-INF folder? Or you'd it inside the WEB-INF/classes folder instead. It should be directly under the WEB-INF folder.

Next, is your servlet under any package? You need to specify the fully qualified class name for the servlet under the <servlet-class> element.

HTH.
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
web.xml is under WEB-INF and Ch1Servlet.class in under classes
WEB-INF\classes | |
| |
web.xml Ch1Servlet.class


soo where did i go wrong?
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i did not use any package and gave servlet class as
<servlet-class>C:\Program Files\Apache Group\Tomcat 4.1\webapps\ch1\WEB-INF\classes\Ch1Servlet</servlet-class>

still its same error
 
Nithya Venkatraman
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Im right, you need to set the response type:
reponseObject.setContentType(String)

After this you can set your Print Writer etc.
Try this out.

Nithya
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i did not use any package and gave servlet class as
<servlet-class>C:\Program Files\Apache Group\Tomcat 4.1\webapps\ch1\WEB-INF\classes\Ch1Servlet</servlet-class>

still its same error
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tried both
response.setContentType("String"); and response.setContentType("text/html");
its still the same........Servlet is fine....the prob must be in the
directory structure only
 
Phani Kumar Sripada
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pallavi,

You shouldn't give the absolute path of the Class file in the <servlet-class> tag. The path should be relative to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ch1\WEB-INF\classes.

In your case you need to give the class name <servlet-class>Ch1Servlet</servlet-class>.

Hope this helps

Regards,
Phani.
 
Sekhar Kadiyala
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pallavi, were you able to make it work or you still need any help!?
 
S Subramonyan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pallavi,

You just need to give the servlet class name if its not packaged.

For eg: you have a class Serv1 in WEB-INF/classes, Serv2 in WEB-INF/classes/com/SCWCD

<servlet>
<servlet-name>name1</servlet-name>
<servlet-class>Serv1</servlet-class>
</servlet>


<servlet>
<servlet-name>name2</servlet-name>
<servlet-class>com.SCWCD.Serv2</servlet-class>
</servlet>

And don't forget to map the url pattern to the servlet name!!!
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
people its still not working for me
i think i need to rephrase my question again

created a servlet named Ch1Servlet and kept its class file under
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ch1\WEB-INF\classes

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

public class Ch1Servlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException{
response.setContentType("text/html");
PrintWriter out= response.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html><body><h1 align=center>HF Chapter1</h1>"+
"<br>"+today+"</body></html>");
}
}


created an xml file name web.xml in
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ch1\WEB-INF

<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_4_1.xsd"
version="4.1.30">
<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>


http://localhost:8080/ch1/Serv1 give the folling error

HTTP Status 404 - /ch1/Serv1

--------------------------------------------------------------------------------

type Status report

message /ch1/Serv1

description The requested resource (/ch1/Serv1) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/4.1.30


its not under any package
 
Arut Jothi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should work if it is under webapps. However try this also,

Please go to your Tomcat 4.1\conf\server.xml and open it thru notepad/some text editor and search for the following :-

<Host name="localhost" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

and insert the follwing thing under that.

<Context path="/ch1"
docBase="C:\Program Files\Apache Group\Tomcat 4.1\webapps\ch1"
debug="5"
reloadable="true" >
</Context>

As per Tomcat 5.x, they suggest that putting <Context path....> should not be part of server.xml. Since you are using tomcat 4.0 and could not solve the problem, so I am suggesting the above.
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is the following in server.xml
<Host name="localhost" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true">
i added this like u said
<Context path="/ch1"
docBase="C:\Program Files\Apache Group\Tomcat 4.1\webapps\ch1"
debug="5"
reloadable="true" >
</Context>
still its the same error

i think i should give up on tomcat and better go back to WSAD!
 
Giju George
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like tomcat is not loading your application. Try changing your web.xml as follows and restart tomcat

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<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>
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
noo that too is not working
 
Sekhar Kadiyala
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pallavi,
Can you email me the servlet code and the web.xml file?
I am really interested to resolve this.
Pls email to these ids
bala.shekhar@aig.com
kbsekhar@yahoo.com
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure i will thanks a lot
 
Arut Jothi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems your web.xml has a problem here. just remove the double quote at the end and put slash.

this is what do you have:-
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee"

this is what should have
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/
 
jack wu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever there is a problem occured,first palce you should go is C:\Program Files\Apache Group\Tomcat 4.1\logs\,see log file for some exception informations!
by the way the standards doGet signature is
 
Tobin Jackson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you probably already know this but.. changes to the web.xml will only take effect after you shutdown and restart tomcat. This is true even when reloadable="true" is set in your context.

tobin
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seems like there is a problem with my tomcat will reinstall it
 
Giju George
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pallavi utukuri:
seems like there is a problem with my tomcat will reinstall it


Anyway, try to install in a directory without spaces.. like C:\Tomcat4.0 etc. I know this sounds silly, but I have read before that the spaces in directory can sometimes create problems, esp to classpath.
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i installed in D:\Tomcat4.1 now
http://localhost:8080/ch1/Serv1 is working
but when i start tomcat, the window is showing a buch of lines and disappearing in a second....does it work like that only or the window has to stay showing that tomcat server has started
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when ever changes are made to servlet and is compiled why doesnt refreshing the web page show the new changed servlet???
 
Giju George
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

but when i start tomcat, the window is showing a buch of lines and disappearing in a second....does it work like that only or the window has to stay showing that tomcat server has started


Normally the tomcat console will stay alive and you would be able to see all the system.out logs there. But if you have installed as a windows service, there won't be any console. And if you try to run the starup script, the window pops us and disappears, since there is another instance of tomcat running. So the best option is, to disable the tomcat windows service and use the startup/shutdown script.



when ever changes are made to servlet and is compiled why doesnt refreshing the web page show the new changed servlet???


For each change in the servlet, you need to restart tomcat to reflect the change. I'm not sure whether there's any other work-around for this .. !!!
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
some times restarting tomcat itself is not working......sometimes the new changes are only visible after rebooting the system! there must be some other way for the new changes to reflet..is there?
 
S Subramonyan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think changes made to the servlet will reflect on the client once you hit the refressh button. But before that check tomcat command prompt to see if "WebappClassLoader ..... updated ..was time1 : now: time2". After you see this in the tomcat window, you can successfully get the modified servlet in the browser. It might take a minute or two.
 
Tobin Jackson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For each change in the servlet, you need to restart tomcat to reflect the change. I'm not sure whether there's any other work-around for this .. !!!


For Tomcat 5, create a file named <web-app-name>.xml. In that file put this:


place this file in $TOMCAT/conf/Catalina/localhost/

For Tomcat 4: I think you can do the above for some of the later versions of tomcat 4. You can also set a Context tag in the server.xml file. try to google the specifics if need be.

hope this helps some folks..

tobin
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanku that did work
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic