*
The moose likes Servlets and the fly likes Access servlet from subdirectory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Access servlet from subdirectory" Watch "Access servlet from subdirectory" New topic
Author

Access servlet from subdirectory

rekha devan
Greenhorn

Joined: Oct 10, 2005
Posts: 26
Hi,

This is my directory structure.

Tomcat home dir>webapps\lessons\WEB-INF \classes\examples\HelloClientServlet.class

and here is my web.xml
-------------------------------------------------------
<servlet>
<servlet-name>HelloClientServlet</servlet-name>
<servlet-class>examples.HelloClientServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloClientServlet</servlet-name>
<url-pattern>/servlet/examples.HelloClientServlet</url-pattern>
</servlet-mapping>
------------------------------------------------------------------
Now I run run Tomcat and try to access the URL
http://localhost:8083/lessons/servlet/examples.HelloClientServlet

It gives this ERROR:
-------------------------------------------------------------------------
javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Thread.java:534)


root cause

java.lang.NoClassDefFoundError: examples/HelloClientServlet (wrong name: HelloClientServlet)
java.lang.ClassLoader.defineClass0(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:539)

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

Now here is the problem. I tried putting HelloClientServlet.class in classes directory and made appropriate changes to web.xml and it works.
But not in the subdirectory classes. I find it very strange. I feel there is no problem with my web.xml file. Am I am missing some configuration here.

Please give you inputs.

Thanks,
Rekha
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

You are trying to use the invoker. It's probably (and properly) disabled.

Create a servlet mapping in your web.xml and use that mapping to activate the servlet.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
rekha devan
Greenhorn

Joined: Oct 10, 2005
Posts: 26
By invoker do you mean in

tomcat_root>conf/web.xml

-----------------------------------------------------
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

==================

<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>


-----------------------------------------------------------
These are uncommented only and also I have done Servlet-mapping in my web application specific web.xml. It is there in my previous posting.

But still does not work :-(
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

The invoker mapping and your mapping are in conflict since they both use the prefix servlet. Disable the invoker and use a prefix in your mapping other than /servlet.
[ February 08, 2006: Message edited by: Bear Bibeault ]
rekha devan
Greenhorn

Joined: Oct 10, 2005
Posts: 26
I did not follow what you are saying .

can you please write using those tags what you meant by prefix.

thanks,
Rekha
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Access servlet from subdirectory