File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet from Servlet to JSP

 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Adeel,

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

I highly appreciate this help.

Cheers,
Swamy.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic