• 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

Pass a resultset to a jsp from servlet

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to pass a ResultSet from a servlet to a JSP in struts 2..
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Create an object that maps to the columns in your resultset and then pass that object or a collection of that object to the JSP. You should not be referencing a resultset directly from the JSP.
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is how I am coding my servlet stuff ...

ArrayList agencyList = new ArrayList();
agency.setLngTransactionId(rSet.getInt("AGCY_TAX_ID"));
agency.setFltCommissionPercentage(rSet.getInt("AGCY_COMSN_PCT"));
agencyList.add(agency);

after this how do I pass this arraylist object to JSP.. Do I need to use any setAttribute functions or something else...
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rahulJ james:
Do I need to use any setAttribute functions or something else...


Yes. request.setAttribute() will do it. (or session.setAttribute() if you need the data on multiple pages.) Then you can use bean:define in the JSP to grab a reference to the list.
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're using struts2 I don't think there is a tag that will give you the ability to get values directly from the request object like you can in struts1. I also don't think that request attributes and parameters get put onto the value stack automatically (if they do I haven't found the correct syntax with which to access them) so you may need to put a scriptlet in your JSP to get the data from your request. If you want to access the values from STRUTS tags with OGNL you'll need to push the value onto the stack.

You could also store the arraylist in your action class and create setters and getters for it. Then your JSP will have access to it and it will be on your OGNL stack automatically.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wouldn't using EL be better than scriptlets?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rahulJ james:
How to pass a ResultSet from a servlet to a JSP in struts 2..



With Struts 2 you can simply provide a public getter method for the result set and use a combination of the <s :p roperty...> tag and OGNL in the JSP.

That said, the previous response that suggested creating a bridge between the result set and the JSP page is a cleaner solution; rather than having to use (pseudo-JSP):



you can say:



Or, if you don't mind mixing paradigms:


[ October 04, 2008: Message edited by: David Newton ]
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't used EL, so if it can do it then its probably better than a scriptlet.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic