Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do i forward db resultset from servlet to jsp  RSS feed

 
Charlie Boss
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm basically trying to forward my resultset, request and response object from my servlet to my jsp script. I'm using Tomcat with IIS for win2000. Please help. I tried:
req.setAttribute ("servlet", "servletName");
getServletConfig().getServletContext().getRequestDispatcher("/jsp/myjsp.jsp").forward(ResultSet, req, res);
my compiler did not recognize the setAttribute and getRequestDispatcher methods.
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to put the data into a bean or a collection. Then put the object of the bean or the collection into session object or
request object. By doing this you will pass the inf.
Hope this is help to you.
Ruilin
 
Charlie Boss
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for answering.. actually forget the resultset part of the question. I'm still getting errors when i compile. how do i send my request and response objects to a jsp. thanks again
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request object is automatically send to JSP when you call JSP from the servlet. You do not need to do anything.
 
Charlie Boss
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still getting a compiler error:
Tag.java:266: cannot resolve symbol
symbol: method getRequestDispatcher (java.lang.String)
location: interface javax.servlet.ServletContext
RequestDispatcher rd = getServletConfig().getServletContext().getRequestDispatcher("tag.jsp");
Please help.. is there anything i have to do to the servlet context in order for me to get my request_dispatcher? or do i have to configure tomcat somehow.. i've added the class files to the classpath so that isn't the problem..
 
Cynthia Yao
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just use getServletContext().getRequestDispatch(".jsp")
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you need to fully qualify the line.

If memory serves, can't you just say :
p.s. request and response are not the implied object in a jsp... this code would work in a servlet, where request and response where passed in on the doPost or doGet method.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you don't need to maintain a reference to the RequestDispatcher:

but that isn't the point I wanted to make.
My opinion (IMHO etc), you DON'T put the data on the session.
This creates unneccessary data that is maintained 'long term' on the server and is therefore a waste of resources. Data placed on the session should ONLY be information that is true for the entire session and is relevant (or valid) for EVERY page. Users go on the session, Shopping Carts go on the session transient, short-lived or 'flag' data should not.
To pass some short lived data from a servlet to a JSP, add the object on the request object then forward the request object to the jsp.

The other thing is that you don't try to write any data or send control somewhere else after this.
Comments?
Dave.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!