• 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

ResultSet from Servlet to JSP

 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JSP and a Servlet.

Now, I pass some date from JSP to Servlet and execute certain query at the servlet.
I would like to return the ResutSet to the same JSP as refered above and populate table there.

Any idea to accomplish this using requestDispatcher.forward()?

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


set your result into some bean or in any collection object, as required. then use

request.setAttribute("bean", bean); or
request.setAttribute("list", arrayList);
it may help
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adeel,

thanks a lot.

I have tried it, but not using ArrayList or Bean.

But just some 3 strings and am setting it to the Request as attributes. When i use request.getParameter at JSP, it is giving me a null value.
And in the following line of the code it gives me Null pointer Exception.



What the error could possibly be.?

Cheers,
Swamy
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adeel,

This is my part of the code for the forward action. Where am i going wrong?



Why am I to user the getServletContext().getRequestDispatcher(jsppage.jsp) What's the difference between this and request.getRequestDispatcher(/file.jsp);

Help needed urgently. Thanks in Advance

Cheers,
Swamy
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


check your getServletContext() value using System.out
check your dispatch object value using System.out

then you will find which one is null.

and in your jsp you should use request.getAttribute(). because you are setting attributes in servlet so can not get parameters. work it out.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getServletContext() will give you an approriate servlet context. for more info you can refer to docs or tutorial (if you have any).
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adeel,

Thanks a lot, man, It's working.....Fine...

I highly appreciate this help.

Cheers,
Swamy.
 
reply
    Bookmark Topic Watch Topic
  • New Topic