Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a compilation/translation error. The code can't compile without the nullary constructor.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic