• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

Passing parameters from a Jsp page that does not have a <form> or page body

From my main JSP that has a form and form elements, I call action.jsp that does some validations and pass the data to java classes.
action.jsp does not have any <form> or  body. But has the return data from my java classes.

I would like to forward the user to thanks.jsp and also display the return data from action.jsp.

How can I pass these parameters to thanks.jsp?
1. I tried to pass as hidden, but since there is no <form>, it does not work.
2. response.redirect did not seem to pass the parameters
3. One suggestion on EE was
RequestDispatcher reqDisp = request.getRequestDispatcher("/thanks.jsp");
reqDisp.include(request, response);
<%@ page errorPage="Exception.jsp" %>

But it does not work either....

When I execute it, the control always goes to exception.jsp and there is no log entires.  Can you tell me what could be the error?
Also, how can I see the actual error mesage when I use <%@ page errorPage tag?
Thank you.
0
mytilig
Asked:
mytilig
  • 3
1 Solution
 
TimYatesCommented:
Store them in the session...

    session.setAttribute( "object1", o1 ) ;
    session.setAttribute( "object2", o2 ) ;

    etc

Then

    session.getAttribute( "object1" ) ;

on the other side...

I would do validation AND processing in action.jsp and then put the results into the session for the next page to pick up after the redirect

Tim
0
 
actonwangCommented:
>>RequestDispatcher reqDisp = request.getRequestDispatcher("/thanks.jsp");
reqDisp.include(request, response);

     This should be a better way because your action.jsp looks like a controller (a servlet like). But here are a few things you need to make sure:

      (1) is "/thanks.jsp" your a correct path? The path is relative to your context root. If your thanks.jsp is inside a subdirectory under your web root, you need to provide it as "/subfolder/thanks.jsp". OR, if thanks.jsp is in the same folde r as action.jsp, just write it as "thanks.jsp" (this might be your choice).
      (2) you might use reqDisp.foward(request,response) instead of reqDisp.include(...).
      (3) you need to put your value into request object in your action.jsp as:
            request.setAttribute("param1",value1);
           and take it out  in thanks.jsp as:
           request.getAttribute("param1").
       
       see this: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/RequestDispatcher.html

     btw: You can look at the log file to see detailed error message.

Enjoy :)
Acton
0
 
actonwangCommented:
Another might be easier way is to use :

<jsp:forward page="thanks.jsp">
   <jsp:param name="param1" value="<%=value1%>" />
</jsp:forward>

The good thing in java world is that you always can come up with a lot of solutions. Unless I find 3 ways to do it, I never stop :)

Enjoy
Acton

 

 
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Ok try out this one.

When you are in action.jsp after validating every thing put the data on to the session using session.setAttribute("SessVar",your variable name");

the forward using jsp:forward to the Thanks page.

And there you retrieve back the data from the session & display.

Thank You.
0
 
actonwangCommented:
shivaspk,

          TimeYate already said that ...

         Also, I already mention jsp:forward and you don't need session if you use that.  I already list all possible solutions VERY clearly. You can look at my comments to learn it.

Acton
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now