aspose file tools*
The moose likes JSP and the fly likes jsp:useBean and jsp:getProperty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:useBean and jsp:getProperty " Watch "jsp:useBean and jsp:getProperty " New topic
Author

jsp:useBean and jsp:getProperty

Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Hello,
I'm trying to learn how to use bean-related standard actions. Would someone please help me resolving this issue? This is the error I'm getting:

Dec 10, 2011 3:52:57 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /web/beerResult.jsp(24,17) The value for the useBean class attribute com.example.domain.Beer is invalid.
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1233)
....

Here's a partial example of what I've done:



Controller:


JSP:


Thanks for reviewing my code and any feedback you can provide.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61412
    
  67

Is the bean's class file in the correct location?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61412
    
  67

And, is the scriptlet in your JSP just for testing purposes? Scriptlets are no longer acceptable in JSP pages.
Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Thanks Bear for your reply. In response to your question, yes and yes. The bean class is here: C:\apache-tomcat-6.0.33\webapps\MyServletApp\WEB-INF\classes\com\example\domain.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
There are three requirements for a java object to be recognised as a Bean

- has to compile (duh)
- has to be in a package
- has to have a public 'default' constructor that takes no arguments.
- should be Serializable.

Your class is missing the third requirement.
ie



One other thing: A JSP implicitly defines a variable called "session", so you shouldn't need to declare your own version of it, but rather use the standard one.
Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Thanks Stefan!!! I'll give this a try and keep these requirements in memory too!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:useBean and jsp:getProperty