wood burning stoves*
The moose likes JSP and the fly likes <jsp:useBean> example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "<jsp:useBean> example" Watch "<jsp:useBean> example" New topic
Author

<jsp:useBean> example

Samaresh Gupte
Greenhorn

Joined: Oct 03, 2009
Posts: 20
Hi,

I have bee trying out an example from head first JSP and Servlets and been recieving jasper excepition.
Can you please help me with the same...

Here is my bean code


and Here is my JSP:


The error I recieve is:
HTTP Status 500 -

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

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Cannot find any information on property 'strName' in a bean of type 'foo.Person'
org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:837)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1011)
org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1062)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3270)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:189)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.


can you please help me out


Regards,
Samaresh Gupte
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
property attribute should be name & empId then it will works....

In property attribute we shuld give name according to geter & setters not real variables in that bean.

Thanks,
Shailesh
Samaresh Gupte
Greenhorn

Joined: Oct 03, 2009
Posts: 20
Thank you Shailesh.It worked

I have another query.

In the bean tag when we set the property to primitive value, does the automatic type conversion take place only when the type and class have the same bean class..say



Now will the same thing work if say:


Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
what is relation between Employee & Person(subclass - superclass) ?
swapnl patil
Ranch Hand

Joined: Aug 13, 2007
Posts: 80
first thing you need to understand the following rule for Bean

1) a bean can have a public method that can be used to set the value of a property. This method is called a
setter method. The method does not return any value, and its name starts with "set" followed by the name of the
property. A setter method has the following signature:



For example, the setter method for the property operand must be named setOperand. Note that the spelling for the
property name is not exactly the same. A property name starts with a lowercase letter, but the name of the setter uses
an uppercase letter after "set"; hence setOperand.

2) a bean can have a public method that can be called to obtain the value of a property. This method is called
a getter method, and its return type is the same as the property type. Its name must begin with "get"; followed by the
name of the property. A getter method has the following signature:



As an example, the getter method for the property named operand is getOperand. A property name starts with a
lowercase letter, but the name of the getter uses an uppercase letter after "get;" hence getOperand.

so your methods name should be

same for get method
also don't need type="foo.Person" in usebean Tag


try this
Samaresh Gupte
Greenhorn

Joined: Oct 03, 2009
Posts: 20
Well thank you Swapnil


what is relation between Employee & Person(subclass - superclass) ?


Sorry forgot to mention the relation

Employee extends Person
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <jsp:useBean> example
 
Similar Threads
problem with type attribute ....
jsp cannot call bean in websphere application server
Simple Jsp-Bean problem !!
Problem Regarding Accessing Java Bean From JSP
problem in jsp:useBean