tags:

views:

35

answers:

2

I have a JSP page which display a list from servlet, it has a textbox which is used to filter the search result. I am selecting a item in the list (table) and redirecting to another page for editing the details after finishing the editing. I am able to come back to the search page via servlet, but I am unable to preserve the search condition in the textbox and its result. How to do that? I am thinking of setting up a session value and get it in search page, is that correct? Or is there any other way?

+1  A: 

Storing it in the session scope is the easiest way but, depending on how big your application is expected to be, it could arise some scalability issues.

As an alternative, when you select an item in the list, you could forward (instead of redirect because if you make a redirect, you lose the request parameters) to another page, passing the search query as a parameter in the request. One possibility is to have a form with two hidden fields (the query and selected item):

<form action="go_to_the_detail">
<input type="hidden" name="selectedItem" value="value_selected_item" />
<input type="hidden" name="query" value="query" />
</form>

In the editing page:

<form action="go_to_save_item">
<input type="hidden" name="query" value="query_obtained_from_the_request" />

item fields to be modified
</form>

So, when the user finishes editing the item, the query will be passed again in order to be displayed in the search box.

Guido
thanks for the tip mr.gracia, but :-) that lead to another question how to do that? any reference or links
sansknwoledge
will try it and will report here.
sansknwoledge
A: 

You can access request parameters in EL by the implicit ${param} variable. You can retain request parameters in the subsequent requests by input type="hidden" element.

Thus, the following basic example should work.

Page A:

<form action="page B">
    <input type="text" name="search" value="${param.search}">
</form>

Page B:

<form action="page A">
    <input type="hidden" name="search" value="${param.search}">
</form>

Keep in mind that those will get lost when you do a redirect instead of a forward inside the servlet, simply because of the fact that a redirect will create a brand new request, hereby garbaging the initial request, including all of its parameters and attributes.

BalusC
thanks balusc and gracia, i am able to run that now. thanks a lot
sansknwoledge