• Post Reply Bookmark Topic Watch Topic
  • New Topic

Importing packages / Instantiating classes in JSP

 
Crace Selvage
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I tried searching for a similar problem in the saloon, but could not find one.

I have created a Message class that has a getter/setter for the String message variable. This class was written in Eclipse in my project's src.entity package and using a test class I can successfully instantiate Message and set/get a message.

package entity;
public class Message {
private String message;
public Message(){}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

The Message.class file is in the root folder for my project, pfl, in Apache Tomcat...Root/pfl/entity. When trying to use this class in a jsp I initially tried using an import page statement for the Message class at the top of my jsp.

<%@ page import="entity.Message" %> but this results in
Generated servlet error:Only a type can be imported. entity.Message resolves to a package

When trying to use a jsp tag
<jsp:useBean id="messageBean" class="entity.Message" /> I get back

org.apache.jasper.JasperException: /pfl/RegistrationConfirmation.jsp(49,0) The value for the useBean class attribute entity.Message is invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Tomcat's log files didn't provide any more detailed information. Can anyone nudge me in the right direction???

Thanks,
Crace
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your class needs to be in the /WEB-INF/classes directory. The package hierarchy starts from there.

[TOMCAT_HOME]/webapps/[yourwebapp]/WEB-INF/classes/entity/Message.class
replace [yourwebapp] with the context for your web app. This may be "Root", but should probably not be.

You mentioned "Root" in your post.
If pfl is its own standalone web-application, then the directory "pfl" should be in the webapps directory, with its own WEB-INF and web.xml.

Hope this helps,
evnafets
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/view?BeansNotFound
 
Crace Selvage
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I moved my project out of the ROOT folder. The absolute path is now C:\Program Files\apache-tomcat-5.5.17\webapps\pfl\WEB-INF\classes\com\craceonline\pfl\process

This solved the problem, as I am able to successfully import and instantiate other classes. Thanks for the help.
Crace
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!