This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes JSP to Servlet Mapping Problem 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 » Products » Tomcat
Bookmark "JSP to Servlet Mapping Problem" Watch "JSP to Servlet Mapping Problem" New topic
Author

JSP to Servlet Mapping Problem

Gary Nitzberg
Greenhorn

Joined: Aug 15, 2011
Posts: 4
In the server.xml file I have a virtual host defined as,

<Host name="domain.com" appBase="/home/webapps/servlets">
<Context path="/" docBase="/home/user/public_html"></Context>
</Host>


In the docBase is an index.jsp file, "/home/user/public_html/index.jsp"
In the appBase is an index.jsp file, "/home/webapps/servlets/index.jsp"
Both index.jsp file are identical.

In the index.jsp file I attempt to use a servlet;

<%@ page import="com.domain.myServlet" %>
<jsp:useBean id="myId" scope="page" class="com.domain.myServlet" />

The servlet is located in, "/home/webapps/servlets/WEB-INF/classes/com/domain/myServlet"


If I execute http://domain.com/index.jsp I get the following error,
"The value for the useBean class attribute com.domain.myServlet is invalid"

If I change the context in the server.xml file to the following it works.
<Context path="" docBase="."></Context>
This is because it executes the index.jsp file in the appBase directory of "/home/webapps/servlets/index.jsp"


It appears the code in the index.jsp file in "/home/user/public_html" can not find the servlets in the appBase.
So how do I tell code in the index.jsp in the public_html directory how to find the servlets in appBase.


Thanks.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15629
    
  15

That's a funny way to use a servlet. Strictly speaking, servlets are executable objects invoked directly from URL requests and not something that you'd include into a JSP with a "useBean" tag. Also, it's strongly discouraged these days to include Context definitions in the Tomcat server.xml file. They should be separate files in the TOMCAT_HOME/conf/Catalina/localhost directory or in the WAR's META-INF/context.xml file.


Customer surveys are for companies who didn't pay proper attention to begin with.
Gary Nitzberg
Greenhorn

Joined: Aug 15, 2011
Posts: 4
I know Tomcat has its own way to map classes.
I have dozens of applications that were developed as far back as 10 years ago using Resin.
The Resin web.xml file allows a classpath configuration,
<classpath id='/home/webapps/servlets/WEB-INF/classes' source='/home/webapps/sources' />
that lets you set the classpath to anywhere you wanted on a host basis.

I have seen a number of posts where porting from Resin to Tomcat becomes difficult due to this exclusion. After all, a JSP page is a servlet that should be able to use a class where-ever it is located.

I guess this is all based on packaging an entire application in a WAR file instead of having pieces of the application all over the place.

I just wish I did not have to reconfigure the all the Resin apps to conform to Tomcat!


I know about the context statement in the TOMCAT_HOME/conf/Catalina/localhost.
I was just trying to make the example simple.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP to Servlet Mapping Problem
 
Similar Threads
Servlet 404 and JkMount configuration - encountered some problem (Apache/Tomcat)
configuration help.
include doesn't recognize relative path from sub folder
My web.xml is good?, why no run my servlets into folder /servlets/ ???
i get diffrent contextpath