wood burning stoves 2.0*
The moose likes Servlets and the fly likes ResultSet from Servlet to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "ResultSet from Servlet to JSP" Watch "ResultSet from Servlet to JSP" New topic
Author

ResultSet from Servlet to JSP

Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
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

Joined: Aug 15, 2004
Posts: 2874


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

Joined: Aug 31, 2004
Posts: 295
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

Joined: Aug 31, 2004
Posts: 295
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

Joined: Aug 15, 2004
Posts: 2874


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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Aug 31, 2004
Posts: 295
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
 
subject: ResultSet from Servlet to JSP
 
Similar Threads
To call a servlet from a JSP
how to redirect from a single servlet to more than one jsp's?
Getting the div values
servlet
Submit the form