0

I am trying to create a search filter and i am posting my form from a jsp page to a servlet and it contains textbox and drop down list and i display the search results on that same jsp page but I want to retain the values in my text box and the values selected in the dropdown list after a response.sendRedirect to that jsp page. please help im just a beginner in java.

  • How are you displaying the search-results on the same jsp page, i.e. are you passing the search-results from the servlet to JSP? How? – Prakash K Aug 17 '12 at 11:38
  • You should not be doing a redirect after post. Just replace post by get. Then you can use param the usual way: http://stackoverflow.com/q/3937624 – BalusC Jan 11 '16 at 07:56

1 Answers1

0

I think a better solution than using a standard form submit and response.sendRedirect combo to do a search and displaying the results on the same page would be to utilize AJAX for the form submit. AJAX stands for Asynchronous Javascript And XML and as such would require that you can use javascript. There are plenty of tutorials around online that explain how to do AJAX based requests, and it's even easier with something like jQuery.

That being said, the only way to persist query parameters through a redirect is to store them outside of the request. The simplest, and probably best, way to do this for your issue is to use the session. Here's a brief example on its basic usage:

String myValue = "myValue";
HttpSession session = request.getSession();
session.setAttribute("myParameter", myValue);
String sameValue = session.getAttribute("myParameter");
NemesisX00
  • 2,046
  • 2
  • 13
  • 12