Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

value for useBean class is invalid

 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my HTML

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<form action="TestBean.jsp">
Name : <input type="text" name="userName">
User ID: <input type="text" name="userID">
<input type="submit">
</form>
</BODY>
</HTML>

TestBean.jsp is like this
<jsp:useBean id="person" type="foo.Person" class="foo.Employee"/>
<% pseron.setName(request.getParameter("userName")); %>

I have also created foo.Person & foo.employee and put them in classes folder.
but I am getting an exception like this org.apache.jasper.JasperException: /TestBean.jsp(1,1) The value for the useBean class attribute foo.Employee is invalid.

Thanks
 
Jan Kostelansky
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not possible to mix scope attributes and method variables.
If a variable is created in scriptlet, it is transformed into regular variable in jsp service method and it is accessible in another scriptlets on the same jsp page.
If a variable is created in jsp declaration, it is transformed into regular instance variable in jsp object and it is accessible in another scriptlets on the same jsp page.
However jsp:useBean standard action does not create variable, it creates attribute in scope defined in scope element.

If you want top use standard action use jsp:setProperty standard action to set property for a bean
If you want to use scriptlets create variable in scriptlet as well
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

<% pseron.setName(request.getParameter("userName")); %>

is the valid code to set the bean attribute. When the useBean is encountered, it create a attribute in given scope as well as create a scripting variable in the current scope ( Java method, {} etc scope) that is if you are not enclosing the useBean in <%{ %> useBean.. <%}%>. The variable with the same name as id of useBean is created in _jspService method.

The above example, I think the error is not do to this statement. Possibility that the Employee class is not subclss of Person class, so the compiler does not accepting it as class attribute.

Thanks
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didnt get u totally. But you can store request parameters in bean properties. And this example is given in HFSJ.

Thanks
 
Sandeep Singh Kunwar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have also created foo.Person & foo.employee and put them in classes folder.
but I am getting an exception like this org.apache.jasper.JasperException: /TestBean.jsp(1,1) The value for the useBean class attribute foo.Employee is invalid.


class foo.employee extends foo.person // this should be class structure and
i think another reason may be
person.setName(String name) // argument must be string
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic