File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes [Solved]Need some clarification about <jsp:useBean/> standard action. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "[Solved]Need some clarification about <jsp:useBean/> standard action." Watch "[Solved]Need some clarification about <jsp:useBean/> standard action." New topic
Author

[Solved]Need some clarification about <jsp:useBean/> standard action.

Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374

Turns into this code in the _jspService() method
[Ref: HFSJ, Page #- 350]
It means if it doesn't find person object then and only then it will create new one. Now my case,


If I don't write no-arg constructor I get
The value for the useBean class attribute com.company.testservlet.command.Dog is invalid error.
But in my servlet I do set dog object in request parameter. Then why does it give me error? :evil:
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Every javabean is expected to have a default no-arg constructor.

Though, I would say, the jsp:useBean is superfluous in MVC.
You already set the bean in the request scope using a servlet.
The bean is already available by ${dog} in the forwarded JSP.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Bauke Scholtz wrote:Every javabean is expected to have a default no-arg constructor.

yeah that's what the conclusion. and I also searched on internet and all over the solution is to include public no-arg constructor.But I am confused after seeing its conversion to servlet. It doesn't actually create an instance if it finds one in the given scope. Then why do I get this error? :twisted:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

It's a compilation/translation error. The code can't compile without the nullary constructor.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Bear Bibeault wrote:It's a compilation/translation error. The code can't compile without the nullary constructor.
Bear, you are a truly genius. But how could somebody guess about this problem, if she doesn't look at the servlet ( come from JSP)?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

The clue should be that <jsp:useBean> expects a bean, and without a nullary constructor the class isn't a bean.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Perfect!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Solved]Need some clarification about <jsp:useBean/> standard action.
 
Similar Threads
useBean and type vs class
Doubt-page356
jsp:useBean
confusion about value attribute expression in <jsp:setProperty>
jsp:useBean conceptual problem