@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/