Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Referenced projects in Tomcat problem
Referenced projects in Tomcat problem [message #515870] Sun, 21 February 2010 23:51 Go to next message
David  is currently offline David Friend
Messages: 4
Registered: February 2010
Junior Member
I've got a project "foo.entities" which contains a bunch of data entity classes.

I've got another project "foo.servlets" which references the entities project. foo.servlets is a Dynamic Web Project that uses Tomcat. I added the reference by going foo.servlets > Properties > Java Build Path > Projects > "foo.entities".

I make use of the entity classes in the Servlet classes fine and it compiles alright (or rather, the IDE gives me no error messages). I also reference the entity classes within JSP files.

I already import it using:

<%@ page imports="foo.entities.*" %>

...but Tomcat gives me this error:


org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 4 in the jsp file: /LoginInfo.jsp
foo.entities.User cannot be resolved to a type
1: <%@ page session="true" import="java.util.*, foo.entities.*" %>
2: <% 
3: 
4: foo.entities.User user = (User)session.getAttribute("user");
5: if( user != null ) { %>
6: 
7: <p>Logged in as <%= user.getID() %> (<%= user.getRoleName() %>).</p>



What's up?

[Updated on: Sun, 21 February 2010 23:52]

Report message to a moderator

Re: Referenced projects in Tomcat problem [message #516032 is a reply to message #515870] Mon, 22 February 2010 14:39 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
David wrote:
> I've got a project "foo.entities" which contains a bunch of data entity
> classes.
>
> I've got another project "foo.servlets" which references the entities
> project. foo.servlets is a Dynamic Web Project that uses Tomcat. I added
> the reference by going foo.servlets > Properties > Java Build Path >
> Projects > "foo.entities".
>
> I make use of the entity classes in the Servlet classes fine and it
> compiles alright (or rather, the IDE gives me no error messages). I also
> reference the entity classes within JSP files.
>
> I already import it using:
>
> <%@ page imports="foo.entities.*" %>
>
> ..but Tomcat gives me this error:
>
>
>
> org.apache.jasper.JasperException: Unable to compile class for JSP:
> An error occurred at line: 4 in the jsp file: /LoginInfo.jsp
> foo.entities.User cannot be resolved to a type
> 1: <%@ page session="true" import="java.util.*, ssc.jdbc.entities.*" %>
> 2: <% 3: 4: foo.entities.User user = (User)session.getAttribute("user");
> 5: if( user != null ) { %>
> 6: 7: <p>Logged in as <%= user.getID() %> (<%= user.getRoleName() %>).</p>
>
>
>
> What's up?

For Java applications it is safe to assume build-time classpath ==
runtime classpath. For Java EE applications, this is not a safe
assumption. Adding the jar on the "Java Build Path" page for a Dynamic
Web Project only affects the build-time classpath. To indicate
"foo.entities" should be deployed with "foo.servlets" to include in its
runtime classpath, go to foo.servlets > Properties > "Java EE Module
Dependencies" and check "foo.entities". Note that the "Java EE Module
Dependencies" page affects both the build-time and runtime classpaths.
If you enable a dependency there, you don't need to add it in the "Java
Build Path" page.

Cheers,
Larry
Re: Referenced projects in Tomcat problem [message #516044 is a reply to message #515870] Mon, 22 February 2010 15:11 Go to previous messageGo to next message
David  is currently offline David Friend
Messages: 4
Registered: February 2010
Junior Member
Thanks.

Before you posted, I got my application to work by building my foo.entities project to a JAR then putting it under WEB-INF\lib.

I've also got another problem:

Right now I've got a web.xml file without any <servlet> or <servlet-mapping> entries, so I can only access *.jsp files.

When I add a <servlet> and <servlet-mapping> entry I can no-longer access anything, including the servlet and mapping I just defined as well as the JSP files present in the filesystem. I get Tomcat 404 errors.
Re: Referenced projects in Tomcat problem [message #516047 is a reply to message #516044] Mon, 22 February 2010 10:36 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
David wrote:
> Thanks.
>
> Before you posted, I got my application to work by building my
> foo.entities project to a JAR then putting it under WEB-INF\lib.

By checking the project on the Java EE Module Dependencies page, it will
automatically be built into a jar for you and deployed to WEB-INF/lib
during publishing. You won't have to manually export it to a jar under
the project's WEB-INF/lib each time you make changes.

>
> I've also got another problem:
>
> Right now I've got a web.xml file without any <servlet> or
> <servlet-mapping> entries, so I can only access *.jsp files.
>
> When I add a <servlet> and <servlet-mapping> entry I can no-longer
> access anything, including the servlet and mapping I just defined as
> well as the JSP files present in the filesystem. I get Tomcat 404 errors.

A malformed web.xml can cause the webapp not to be served. This is the
most likely cause for your JSPs not being available. You should see
some complaint in Tomcat's log output.

Cheers,
Larry
Re: Referenced projects in Tomcat problem [message #516088 is a reply to message #515870] Mon, 22 February 2010 18:13 Go to previous messageGo to next message
David  is currently offline David Friend
Messages: 4
Registered: February 2010
Junior Member
I've since added the EE reference and it works great, thank you.

As for the web.xml problems:

This is my current web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
	
	<display-name>foo.servlets</display-name>
	
	<welcome-file-list>
		<welcome-file>LoginPage.jsp</welcome-file>
	</welcome-file-list>
	
</web-app>


My LoginPage.jsp servlet has this form element:

<form action="/foo.servlets/LoginServlet" method="post">


...which causes Tomcat to give this error when submitting the form:

HTTP Status 404 - /foo.servlets/LoginServlet

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

type Status report

message /foo.servlets/LoginServlet

description The requested resource (/foo.servlets/LoginServlet) is not available.


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

Apache Tomcat/6.0.14


So I modify my web.xml like so:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
	
	<display-name>foo.servlets</display-name>
	
	<welcome-file-list>
		<welcome-file>LoginPage.jsp</welcome-file>
	</welcome-file-list>
	
	<servlet>
		<servlet-name>LoginServlet</servlet-name>
		<servlet-class>foo.servlets.LoginServlet</servlet-class>
	</servlet>
	
	<servlet-mapping>
		<servlet-name>LoginServlet</servlet-name>
		<url-pattern>/foo.servlets/LoginServlet</url-pattern>
	</servlet-mapping>
	
</web-app>


Unlike my post earlier, I can now access /foo.servlets/LoginPage.jsp fine and it doesn't give me any errors. However attempting to access 'http://localhost:8080/foo.servlets/LoginServlet' still gives me 404 errors identical to the one above.

Thank you for your help.
Re: Referenced projects in Tomcat problem [message #516149 is a reply to message #516088] Mon, 22 February 2010 21:04 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
David wrote:
> I've since added the EE reference and it works great, thank you.
>
> As for the web.xml problems:
>
> This is my current web.xml:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
> version="2.5">
>
> <display-name>foo.servlets</display-name>
>
> <welcome-file-list>
> <welcome-file>LoginPage.jsp</welcome-file>
> </welcome-file-list>
>
> </web-app>
>
>
> My LoginPage.jsp servlet has this form element:
>
>
> <form action="/foo.servlets/LoginServlet" method="post">
>
>
> ..which causes Tomcat to give this error when submitting the form:
>
>
> HTTP Status 404 - /foo.servlets/LoginServlet
>
> ------------------------------------------------------------ --------------------
>
>
> type Status report
>
> message /foo.servlets/LoginServlet
>
> description The requested resource (/foo.servlets/LoginServlet) is not
> available.
>
>
> ------------------------------------------------------------ --------------------
>
>
> Apache Tomcat/6.0.14
>
> So I modify my web.xml like so:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
> version="2.5">
>
> <display-name>foo.servlets</display-name>
>
> <welcome-file-list>
> <welcome-file>LoginPage.jsp</welcome-file>
> </welcome-file-list>
>
> <servlet>
> <servlet-name>LoginServlet</servlet-name>
> <servlet-class>foo.servlets.LoginServlet</servlet-class>
> </servlet>
>
> <servlet-mapping>
> <servlet-name>LoginServlet</servlet-name>
> <url-pattern>/foo.servlets/LoginServlet</url-pattern>
> </servlet-mapping>
>
> </web-app>
>
>
> Unlike my post earlier, I can now access /foo.servlets/LoginPage.jsp
> fine and it doesn't give me any errors. However attempting to access
> 'http://localhost:8080/foo.servlets/LoginServlet' still gives me 404
> errors identical to the one above.
>
> Thank you for your help.

Sorry to take so long. If you haven't already figured it out, it should be:

<url-pattern>/LoginServlet</url-pattern>

The "foo.servlets" in the URL identifies the webapp. The <url-pattern>
provides the "location" within the webapp.

Cheers,
Larry
Re: Referenced projects in Tomcat problem [message #516150 is a reply to message #515870] Mon, 22 February 2010 21:16 Go to previous message
David  is currently offline David Friend
Messages: 4
Registered: February 2010
Junior Member
Thank you ever so much, my web project now runs and all is good. Smile
Previous Topic:Next question - where to create application.xml file for EAR web service project?
Next Topic:access to the Web Services Explorer generated UI
Goto Forum:
  


Current Time: Fri Mar 29 12:26:19 GMT 2024

Powered by FUDForum. Page generated in 0.02860 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top