javascript - 即使搜索完成后我也想保留我的输入字段数据

标签 javascript java spring

@RequestMapping(value= "/search")
public String personList(@ModelAttribute("employee") Employee e,ModelMap map,@RequestParam("drop") String value) 
{
    /*System.out.println("In Controller " + e.getEmployeeName() +" "+ value);*/
    map.put("drop",value);
    map.put("employee",e);
    map.put("employeeList", employeeService.employeeList(e.getEmployeeName(),value)); 
    return "ViewPage";
}

上面是我的 Controller 代码

<form:form  action="search.html" modelAttribute="employee" method="POST">

<select id="ViewByName" class ="dropdown" name= "drop">
 <!-- <option value="r">Select....</option>  -->
  <option value="s">Starts With</option>
  <option value="c">Consist Of</option>
  <option value="e">Ends With</option>
</select>

            <div id="search-inner">
                <td>
                <form:input path="employeeName" type="text" name="search" maxlength="30" id="searchfield" title="searchfield" value="type the name of employee to search..." class = "search" 
                onfocus="if (this.value=='type the name of employee to search...') this.value=''" 
                 onblur="if (this.value == '') this.value ='type the name of employee to search...'"/>

              <input type="submit" name="Search" value="Name Search"   title="Search" />

                </td>
            </div>
</form:form>

以上是我的JSP页面代码。 我的问题是,当我从下拉列表中选择某个选项并在搜索后根据下拉值输入文本输入搜索时,我的输入字段会转到默认文本,但我想将其保留在搜索结果页面中。

最佳答案

您可以使用请求参数,如下所示:

@RequestMapping(value= "/search")
public String personList(@ModelAttribute("employee") Employee e,ModelMap     map,@RequestParam("drop") String value,HttpServetRequest request) 
{
    request.setparameter("searchdata",drop);
    /*System.out.println("In Controller " + e.getEmployeeName() +" "+ value);*/
    map.put("drop",value);
    map.put("employee",e);
       map.put("employeeList",employeeService.employeeList(e.getEmployeeName(),value)); 
    return "ViewPage";
}

在jsp页面上你可以获得像这样的值

<%= request.getParameter("searchdata") %>

关于javascript - 即使搜索完成后我也想保留我的输入字段数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34870485/

相关文章:

javascript - Node.js 中 util.format() 的补充函数

php - 在页面/浏览器关闭/退出时自动保存/提交表单

java - 使用 now() sql 将小时和分钟添加到 hql

java - 它不断出现 'Cannot find symbol'错误

java - 使用 Webclient - Webflux 将两个 api 响应合并为一个

java - 如何配置嵌入式jetty 9动态重新加载静态内容?

java - JPA EntityManager 大内存问题

javascript - 为什么以下函数在 Safari 中无法检测浏览器语言?

javascript - 函数 "onclick"被调用,即使它没有在按钮中设置

java - 使用 MongoOperations 删除 Mongo 上的多个数组条目