954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Redirect to a page with parameters

Hello, I am new to web development.

I have a page file1.jsp with a form, the submitted data is handled in file2.jsp, and I want to show the answer in the same page, file1.jsp.
After the data be handled in file2.jsp, I want to reload file1.jsp and show the answer.

In file2.jsp, I tried to use response.sendRedirect(), but it does not include parameters or POST data, and I need to send the answer.

I cannot use GET and Ajax.

Hand
Newbie Poster
9 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

You can submit to the same page: file1.jsp and do the processing there. Take the data from the request. The first time you go to the page, the request will be empty so you can use that check. When you submit then you request will not by null:

file1.jsp

<form action="file1.jsp" >
  <input type="text" name="data_1" />
</form>


When you submit to the same page:

String data1 = request.getParameter(data_1);


But the first time you go to the page there will not be any data_1 in the request so:

file1.jsp

String data1 = request.getParameter(data_1);

if (data1!=null) {
  // calcuate data
  // get answers
}

<body>
  <%
  if (data1!=null) {
  %>
    //  show answers
  <%
  }
  %>

<form action="file1.jsp" >
  <input type="text" name="data_1" />
</form>
</body>
javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 


It works.
Thank you.

Hand
Newbie Poster
9 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: