• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<jsp:useBean> example

 
Samaresh Gupte
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Samaresh Gupte
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is relation between Employee & Person(subclass - superclass) ?
 
swapnl patil
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well thank you Swapnil


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


Sorry forgot to mention the relation

Employee extends Person
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic