Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

useBean problem  RSS feed

 
Beda Tsang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Oh...thank you both.

I got it now.

Thanks.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!