0

Here is my code, how can i retain the values of the form when i click on the hyper reference link.(a href: bottom of the code)

<form action="APPServlet">
    <div class="">
        <div class="">Search For:</div>
        <div class="">
            <input type="text" size="45" align="right" name="searchRequest">
        </div>
    </div>
    <div class="">
        <div class="">Exclude:</div>
        <div class="">
            <input type="text" size="45" align="right" name="excludeWords">
        </div>
    </div>
    <div class="">
        <div class="">In Modules:</div>
        <div class="">
            <select name="modules">
                <option name="module" value="all">All modules</option>
                <c:forEach var="module" items="${modelObj.modules}">
                    <option name="module" value="${module}">${module}</option>
                </c:forEach>
            </select>
        </div>
    </div>
</form>

<!--  ahref outside the form , this does not work
    &searchRequest=${searchRequest} <- Guess the value is out of scope
-->
<div class="div-table-row">
    <div class="div-table-single-col">
        ${question.id} <a href="APPServlet?id=${question.id}&searchRequest=${searchRequest}">${question.topic}</a>
    </div>
</div>  
Arun Abraham
  • 4,011
  • 14
  • 54
  • 75
  • You could simply add the `value` attribute to these textboxes - `value=${param.serchRequest}` and `value="${param.excudeWords}"`. Be sure to pass them as parameters to querystring as you're using the link. If I were you, then I would be more of using a backing bean for this purpose. – Lion Mar 03 '13 at 15:31

3 Answers3

1

You have several possibilities, and all involve JavaScript.

  1. When clicking on the link, change its href using JavaScript by appending all the values of the inputs of the form as parameters of the URL

  2. When clicking on the link, add a hidden field to the form containing the question ID, change the action of the form to make it go to MCQApp instead of going to APPServlet, and submit the form

  3. The cleanest one: when clicking on the link, send an AJAX request to a URL which responds with an HTML fragment (or data), and replace the section of the page that you want to update with this HTML fragment, thus leaving the form as it is in the page.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

There are two ways, if you're working with a session, store it as an attribute of your session. But if you're not using sessions, you can use Cookies, just store the values you want in a new cookie and then call the cookie and obtain the values.

Sessions are cookies as well, but they have another functions, the cookies are simplier and help you to store values that you can reuse later. Best regards

Marcelo Tataje
  • 3,849
  • 1
  • 26
  • 51
0

Keep the data passed in a model and use it in the jsp like,

Keep all your Input variables in search model object and update it whenever search is called.Keep searchRequest in the request attribute before rendering the response.

Avinash Singh
  • 3,421
  • 2
  • 20
  • 21