• 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

useBean problem

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,
I am new to JSP and Servlet and now studying a book for SCWCD.
I have a set of JSP code as follows:


<html><BODY>
<jsp:useBean id="person" class="com.translate.Aclass" scope="request"/>
</BODY>
</html>



Where the class com.translate.Aclass does not exists. However the book said that it would automatically create one for me when it compiles. But the result is the compiler gives an error message.

"org.apache.jasper.JasperException: /test2.jsp(4,0) The value for the useBean class attribute com.translate.Aclass is invalid."


What is wrong ? Is there anything I have missed?

Would anybody help? Thank You.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post a bit of your com.translate.Aclass.java ?
What is Aclass ?
 
Beda Tsang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neither Aclass nor Aclass.java exists.
Or...do I misunderstand my book.
I expect it would automatically generate a class for me when the JSP compiles. Something like what "request.getSession()" do.

The book said it would generate the class in the _jspService() method.
However, the error occur when the JSP turns into the servlet.
 
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Create a bean with package and compile and Place the class file in the WEB-INF eg: WEB-INF/Classes/com/translate/Aclass .Now use the code


It will work .

bye for now
sat
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I expect it would automatically generate a class for me when the JSP compiles.


Oops, little misunderstanding here. Do you expect the container to create a class out of thin air ?

What your book tries to tell you is :
When a bean does not exist in the specified scope, useBean will instanciate a new bean of the type specified in the class attribute.

In your example, it will try to do : "new com.translate.Aclass". You have to provide the container the "com.translate.Aclass" class.
 
Beda Tsang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh...thank you both.

I got it now.

Thanks.
reply
    Bookmark Topic Watch Topic
  • New Topic