0

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.

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Hand
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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.