aspose file tools*
The moose likes Servlets and the fly likes Not able to run servlet-HTTP status404 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Not able to run servlet-HTTP status404 " Watch "Not able to run servlet-HTTP status404 " New topic
Author

Not able to run servlet-HTTP status404

Chetan Dodiya
Ranch Hand

Joined: Jun 27, 2008
Posts: 39
hi...
I am new to servlet....
when I am try to run servlet in my browser it gives error HTTP status 404

my setting is:

path=D:\Java\jdk1.5.0_06\bin;D:\Java\JSDK2.0\bin
classpath=D:\Java\jdk1.5.0_06\lib\tools.jar;D:\Java\JSDK2.0\lib\jsdk.jar
java_home=D:\Java\jdk1.5.0_06
tomcat_home=D:\Java\tomcat


and the problem I am trying to run is given in HF S&J pg. no.- 30...
I done as per stated in the book but while I am trying to run the servlet it gives the same problem again again...
my web.xml and ch1Servlet are correct....
please help me to sortout this problem....


SCJP 1.5
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

You may have something missing in your servlet mapping ... Please give more details regarding your servlet you are trying to invoke,full stack trace etc.. BTW have you checked whether your application is deployed properly?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Chetan Dodiya
Ranch Hand

Joined: Jun 27, 2008
Posts: 39
my ch1Servlet file is below and its .class file is in the tomcat/webapps/ch1/WEB-INF/classes folder...

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

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\'s Chapter1 Servlet</h1>"+
+ today +"</body>"+"</html>");
}
}

and its .xml file is below and it is in the tomcat/webapps/ch1/WEB-INF folder...

<?xml version="1.0" encoding="ISO-8851-1" ?>
<web-apps 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/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-apps>



and my tomcat starts perfectly......
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

You have wrong tag <web-apps> instead <web-app> in web.xml.
Ant BTW you have put your servlet in default package. That's considered a bad practice. First try moving it in to a package and change the web.xml accordingly (changing the <servlet-class> tag value). And are you able to access the default (index) page for tomcat (http://hostname:port/) ? How you are accessing the servlet (URL) ?
Chetan Dodiya
Ranch Hand

Joined: Jun 27, 2008
Posts: 39
yes....
I am able to access indiex page correctly...
I am accessing index page using http://localhost:8080
and i forget to tell you that my servlet-api.jar file is in the

tomcat/common/lib folder
and I am new to servlet so I am following as per the suggested in the book...
you can suggest me where should I put my files....
and one more thing....
when I starts tomcat through command prompt, tomcat starts with lots of error in the

command prompt stating that errors in the ch1 folder which is in the tomcat/webapps folder...
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

when I starts tomcat through command prompt, tomcat starts with lots of error in the
command prompt stating that errors in the ch1 folder which is in the tomcat/webapps folder...


First as I said in previous reply, your web.xml file has an error. Change the starting <web-apps.......> to <web-app.....> and ending </web-apps> to </web-app>. If you haven't done that first change it and restart the tomcat, if again errors appear, post the stack trace, then people able to see what's wrong.

and i forget to tell you that my servlet-api.jar file is in the
tomcat/common/lib folder


You don't have to do anything there. servlet-api.jar comes with the tomcat.

Chetan Dodiya
Ranch Hand

Joined: Jun 27, 2008
Posts: 39
Yes...
I am done the same thing as you suggested.....

starting with

<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/web-app_2_4.xsd"
version="2.4">



and ends with

</web-app>

but I am still facing the same problem...

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Please post your stack trace (what you see in the prompt when tomcat starting).
Chetan Dodiya
Ranch Hand

Joined: Jun 27, 2008
Posts: 39
this the output of prompt which shows the many errors when i startup Tomcat..

Jan 7, 2009 1:44:52 PM org.apache.catalina.core.AprLifecycleListener lifecyc
ent
INFO: The Apache Tomcat Native library which allows optimal performance in p
ction environments was not found on the java.library.path: D:\Java\jdk1.5.0_
in;.;D:\WINDOWS\system32;D:\WINDOWS;D:\Java\jdk1.5.0_06\bin;D:\Java\JSDK2.0\
Jan 7, 2009 1:44:52 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jan 7, 2009 1:44:53 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2313 ms
Jan 7, 2009 1:44:53 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jan 7, 2009 1:44:53 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.27
Jan 7, 2009 1:44:53 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jan 7, 2009 1:44:55 PM org.apache.catalina.startup.ContextConfig application
onfig
SEVERE: Parse error in application web.xml file at jndi:/localhost/ch1/WEB-I
eb.xml
java.io.UnsupportedEncodingException: ISO-8851-1
at sun.io.Converters.getConverterClass(Converters.java:218)
at sun.io.Converters.newConverter(Converters.java:251)
at sun.io.ByteToCharConverter.getConverter(ByteToCharConverter.java:
at sun.nio.cs.StreamDecoder$ConverterSD.<init>(StreamDecoder.java:22
at sun.nio.cs.StreamDecoder$ConverterSD.<init>(StreamDecoder.java:21
at sun.nio.cs.StreamDecoder.forInputStreamReader(StreamDecoder.java:
at java.io.InputStreamReader.<init>(InputStreamReader.java:83)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.createRe
(XMLEntityManager.java:2012)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$ScannedE
y.setReader(XMLEntityManager.java:2455)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.setEncod
XMLEntityScanner.java:188)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScanne
l.scanXMLDeclOrTextDecl(XMLDocumentFragmentScannerImpl.java:734)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$XM
lDispatcher.dispatch(XMLDocumentScannerImpl.java:721)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScanne
l.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.par
ML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.par
ML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLPar
java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.pars
stractSAXParser.java:1242)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1562
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(Co
tConfig.java:348)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.jav
48)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextC
g.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Life
eSupport.java:120)
at org.apache.catalina.core.StandardContext.start(StandardContext.ja
148)
at org.apache.catalina.core.ContainerBase.addChildInternal(Container
.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.jav
0)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig
a:927)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConf
ava:890)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1150
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.
:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Life
eSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1

at org.apache.catalina.core.StandardHost.start(StandardHost.java:736
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java
)
at org.apache.catalina.core.StandardService.start(StandardService.ja
48)
at org.apache.catalina.core.StandardServer.start(StandardServer.java
)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorI
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodA
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Jan 7, 2009 1:44:56 PM org.apache.catalina.startup.ContextConfig start
SEVERE: Marking this application unavailable due to previous error(s)
Jan 7, 2009 1:44:56 PM org.apache.catalina.core.StandardContext start
SEVERE: Error getConfigured
Jan 7, 2009 1:44:56 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/ch1] startup failed due to previous errors
Jan 7, 2009 1:44:57 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jan 7, 2009 1:44:58 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jan 7, 2009 1:45:01 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/3016 config=null
Jan 7, 2009 1:45:01 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jan 7, 2009 1:45:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 8859 ms
stef li
Greenhorn

Joined: Jan 16, 2006
Posts: 27
1. use http://ip:port/Serv1 to visit your servlet. Make sure that "S" is upper case
2. or change your web-app's dtd to 2.3version,like below:

3. show your error trace


This guy is so lazy!!!<br />There is nothing left!
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

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


part top of <web-app..> tag.

I think you better copy the <web-app..> part from the ...webapps/ROOT/WEB-INF/web.xml file to your application web.xml then try it. Make sure you copy the above mentioned line as well.

Chetan Dodiya
Ranch Hand

Joined: Jun 27, 2008
Posts: 39
i changed my web.xml file to



and I am starting my tomcat with http://localhost:8080
tomcat starts successfully shows its index page accurately....

when i startup my tomcat through command prompt it displays like...

Jan 7, 2009 2:09:55 PM org.apache.catalina.core.AprLifecycleListener lifecycleEv
ent
INFO: The Apache Tomcat Native library which allows optimal performance in produ
ction environments was not found on the java.library.path: D:\Java\jdk1.5.0_06\b
in;.;D:\WINDOWS\system32;D:\WINDOWS;D:\Java\jdk1.5.0_06\bin;D:\Java\JSDK2.0\bin
Jan 7, 2009 2:09:55 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jan 7, 2009 2:09:55 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2172 ms
Jan 7, 2009 2:09:56 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jan 7, 2009 2:09:56 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.27
Jan 7, 2009 2:09:56 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jan 7, 2009 2:09:59 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jan 7, 2009 2:10:00 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jan 7, 2009 2:10:00 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/484 config=null
Jan 7, 2009 2:10:00 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jan 7, 2009 2:10:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 5281 ms



and in book it sugests that start as http://localhost/ch1/Serv1 and when i hit enter it shows


HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class ch1Servlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)
root cause

java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class ch1Servlet with modifiers ""
sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
java.lang.Class.newInstance0(Class.java:344)
java.lang.Class.newInstance(Class.java:303)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

You are almost there. Just change the access modifier to public in the "ch1Servlet" (public class ch1Servlet .......). Then recompile and deploy it. It should work now.
Chetan Dodiya
Ranch Hand

Joined: Jun 27, 2008
Posts: 39

Hurray!!! now its working thanks alot Vijitha
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

You are welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to run servlet-HTTP status404