• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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

 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Sheriff
Posts: 67651
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67651
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic