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.

Recommended Answers

All 2 Replies

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>

It works.
Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.