• 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

How to use a jsp:useBean inside a Servlet

 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am submitting data from a JSP to a Servlet .



How can i use this jsp:useBean inside my servlet so that i can set data automatically and transfer this User Object to the DAO Layer

Thanks in advance.
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can't, but you can stuff the object into a session or request attribute.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't i use hrad coded HTML in my servlet and pass this Object ??
 
Ryan Beckett
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can't use template text in a servlet, although you can pass HTML through the HttpServletResponse.OutputStream object. Where does HTML come into play here? Here's a quick example of how you would pass an object from a jsp page to a servlet using the request object.




 
Sheriff
Posts: 67746
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

PavanPL KalyanK wrote:
I am submitting data from a JSP to a Servlet


This is not done with a request dispatcher.

So, are you submitting or dispatching? (The latter would be very weird.)

If submitting, the JSP and servlet are executing under different requests. Back up a minute and explain why you are trying to do this. It's rasing all sorts of red flags.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear , i did not get what you said but this is what i am trying to explain .

The User data on to Form (From JSP) is submitted to a servlet only know

Let me explain :




Inside my servlet



There are many setter fields so instead of doing all these , i want to use jsp:useBean facility inside the servlet.
 
Bear Bibeault
Sheriff
Posts: 67746
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
Ah, now I understand. There is no analogous operation build into the Servlet specification. You can either set each, or you could use bean reflection to write your own that does the same thing as the useBean action. Or you might be able to find a 3rd party implementation.

Personally, in such situations I don't use a bean at all; I use a Map wrapped in a class that provides the getters. I don't need setters at all as the name/values pairs are already captured in the Map instance.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks , Could you please tell me or point out to a link "you could use bean reflection to write your own that does the same thing as the useBean action"

 
Bear Bibeault
Sheriff
Posts: 67746
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 bean classes in java.bean as well as the general reflection abilities built into Java let you find the setters for a particular property name.

It can be a bit messy, so before you go that route, I'd suggest looking into my Map wrapper scheme.
 
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Map Wrapper .http://java.sun.com/docs/books/tutorial/collections/implementations/wrapper.html
 
Bear Bibeault
Sheriff
Posts: 67746
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
Please check your private messages for an important administrative matter.
 
Ryan Beckett
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's wrong with the code you have in your servlet? The useBean action tag is for JSP ONLY.
 
Bear Bibeault
Sheriff
Posts: 67746
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
He wants to automatically populate the bean with the request parameters without having to enumerate each property.
 
Ryan Beckett
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Obviously you would use the setProperty action in JSP, but how is that possible in a servlet without using setter methods?

 
Bear Bibeault
Sheriff
Posts: 67746
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

Ryan Beckett wrote:Obviously you would use the setProperty action in JSP, but how is that possible in a servlet without using setter methods?


That is exactly the conversation we've been having.
 
reply
    Bookmark Topic Watch Topic
  • New Topic