• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

value for useBean class is invalid

 
Ranch Hand
Posts: 77
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic