我试图通过表单将搜索方法实现到JSP中,但是我仍然坚持将表单中的文本进一步发送到提交操作。直到现在我做了类似的事情:< / p>
<form onsubmit="location.href='news.do?action=Search&search_string=${search}'" >
Search: <input type="text" name="search">
</form>
答案 0 :(得分:0)
<%
String query = (request.getParameter("query")!=null && request.getParameter("query").trim().length()>0)?request.getParameter("query").trim():"";
if(action!=null && action.trim.equalsIgnoreCase("search"))
{
//do the search
}
%>
<form action="<%=application.getContextPath() + "/my.jsp"%>" method="post">
<input type="hidden" name="action" value="search" />
<input type="text" class="text" value="<%=(request.getParameter("query")!=null && request.getParameter("query").trim().length()>0)?request.getParameter("query").trim():"Search"%>" name="query" />
</form>
答案 1 :(得分:0)
如果您想将表单作为GET而不是POST提交,那么这个怎么样?
<form method = get action="news.do" >
<input type="hidden" name="action" value = "Search">
Search: <input type="text" name="search_string">
</form>
这将向news.do?action=Search&search_string=fsdfdsf
发送请求