@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";
}
以上是我的控制器代码
<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页面代码。 我的问题是当我从下拉列表中选择一些选项并在搜索后根据下拉值输入文本条目搜索时我输入字段转到默认文本但我想将其保留在搜索结果页面中。
答案 0 :(得分:1)
编辑后记录
解决方案只是转变你的价值=&#34;&#34;占位符=&#34;&#34;在搜索输入字段上。
价值覆盖了来自绑定的信息。
答案 1 :(得分:1)
您可以使用请求参数,如:
@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") %>
答案 2 :(得分:0)
请更改以下代码:(jsp)
<form:input path="employeeName" type="text" name="search" maxlength="30" id="searchfield" title="searchfield" class = "search" value="${not empty employee.employeeName? employee.employeeName : 'type the name of employee to search'}" />
并添加jQuery:
$(document).ready(function() {
$("#searchfield").focus(function(){
if (this.value == "type the name of employee to search")
{
this.value = "";
$(this).css('color','#000000');
}
});
$("#searchfield").blur(function(){
if (this.value == "")
{
this.value = "type the name of employee to search";
$(this).css('color','#a9a9a9');
}
});});
答案 3 :(得分:0)
IN jsp而不是value =&#34;输入要搜索的员工姓名...&#34; 占位符=&#34;键入要搜索的员工姓名...&#34;应该使用然后它工作正常并且即使在搜索完成后也保留输入字段数据。 谢谢你的所有建议......
答案 4 :(得分:0)
<form:input path="employeeName" type="text" name="search" maxlength="30" id="searchfield" title="searchfield" placeholder="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...'"/>