aspose file tools*
The moose likes Servlets and the fly likes Need Help with Simple Servlet (my first servlet) 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 "Need Help with Simple Servlet (my first servlet)" Watch "Need Help with Simple Servlet (my first servlet)" New topic
Author

Need Help with Simple Servlet (my first servlet)

K DeLucia
Ranch Hand

Joined: Apr 11, 2008
Posts: 68
I'm attempting to get a simple servlet running on Tomcat 6. I created my html code, java code, etc in Eclipse 3.3.2. I exported the code to a TestServlet.war file and put it into the Tomcat root\webapps folder. I am able to bring up the html page (http://localhost/TestServlet/default.html) and enter some text. When I submit the form I get a 404 error in the browser:
The requested resource (/servlet/ExampServlet) is not available.

This is the HTML code in my default.html file:



This is my servlet code:



This is my web.xml:



The tomcat logs indicate the following problem/stack trace:
Jan 2, 2009 4:00:40 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet org.apache.catalina.INVOKER.ExampServlet as unavailable
Jan 2, 2009 4:00:40 PM org.apache.catalina.core.ApplicationContext log
SEVERE: Error loading WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@15ee671
ExampServlet
java.lang.ClassNotFoundException: ExampServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1083)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:361)
at org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:170)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:619)
Jan 2, 2009 4:00:40 PM org.apache.catalina.core.ApplicationContext log
SEVERE: invoker: Cannot allocate servlet instance for path /servlet/ExampServlet
javax.servlet.ServletException: Wrapper cannot find servlet class ExampServlet or a class it depends on
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:361)
at org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:170)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: ExampServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1083)
... 17 more


I've been researching this all day and I'm not getting anywhere. Does anyone have any ideas on what could be causing the problem? What I can check to try to get this working? Thanks for any and all suggestions.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Why does your action start with "/servlet"? And why doesn't it match your mapping?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Deepa Korecherla
Ranch Hand

Joined: Jul 14, 2004
Posts: 197
Change the URL in the form action to TestServlet. The mapping is thru TestServlet not ExampServlet.


DKR<br />SCJP1.2,SCWCD1.4,SCBCD1.3,SCJA
Deepa Korecherla
Ranch Hand

Joined: Jul 14, 2004
Posts: 197
oh did not check the /* after the TestServlet....thought you were referring to /TestServlet
K DeLucia
Ranch Hand

Joined: Apr 11, 2008
Posts: 68
I've got it working now. I wasn't completely understanding how all the pieces fit together (obviously) but you gave me a shove in the right direction. Now to get it to actually do something worthwhile . . .

Thanks again!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need Help with Simple Servlet (my first servlet)