passing request to a second jsp

Hi Guys

I have a jsp (search.jsp) that deals with a request from a web form and shows the results in the browser. Im then trying to pass this request to a second jsp (export.jsp) to put the info into an xls file. I can create an xls file on its own by setting the contentType but i cant show the results in a browser and then pass the request to export. Ive read loads of foums and tried jsp:forward and jsp:include both of which dont work. I have also tried requestDispatcher and sendRedirect but cant get it to work.

This is the main problem

Provide a href link capable of either calling export.jsp and passing the request or providing a href link to call a method in search.jsp that will then use a method to pass the request and forward the user.

I have been stuck on this for ages now and have had zero luck. If anyone can help me and provide some sample code that would be brilliant.

Thanks

[934 byte] By [Ryion69a] at [2007-11-27 10:48:39]
# 1

Put the request in a session variable.

In the first page do

request.getSession().setAttribute("var", yourData);

and in the second page, just get the data from the session

request.getSession().getAttribute("var");

Manuel Leiria

manuel.leiriaa at 2007-7-28 22:28:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

thanks for the reply

so is:

yourdata

simply the request with some var identifier?

Ryion69a at 2007-7-28 22:28:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

yes, it may be anything. HashTable/ArrayList/String/int/boolean/etc.,

String myVar = myBO.getVal();

session.setAttribute("value", myVar);

JSP:

String getData = (String)session.getAttribute("value");

skp71a at 2007-7-28 22:28:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

What kind of data do you want to pass(String, ArrayList...)?

Manuel Leiria

manuel.leiriaa at 2007-7-28 22:28:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi im actually trying to pass the request (a HttpServletRequest object) but when i use the methods suggested above i get an error cannot cast from Object to [type].

I could do the task by passing a formdata object (my own class) and a boolean instead of the request.

I have tried with a boolean and the HttpServletRequest but always get the same error!

Message was edited by:

Ryion69

Ryion69a at 2007-7-28 22:28:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

if you want to pass alot of values each time, it is usefull to create an object for that and just pass the object around (instead of sending and fetching like 12 values each time)

radicjesa at 2007-7-28 22:28:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Can you post the code (specially the objects you want to pass)

manuel.leiriaa at 2007-7-28 22:28:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Hi Everyone

I have finally got it all working in the end i used a combination of all your advice.

I put all the variables i needed into an object and just passed that using set/getAttribute("value") which worked for my FormData object but would not work for a boolean or HttpServletRequest!

Stars all round!

Ryion69a at 2007-7-28 22:28:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

Glad to help!

Manuel Leiria

manuel.leiriaa at 2007-7-28 22:28:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...