0
我試圖通過表單實現一個搜索方法到JSP中,但我堅持發送文本從表單進一步提交action.I作出這樣的事情直到現在:JSP搜索表格
<form onsubmit="location.href='news.do?action=Search&search_string=${search}'" >
Search: <input type="text" name="search">
</form>
我試圖通過表單實現一個搜索方法到JSP中,但我堅持發送文本從表單進一步提交action.I作出這樣的事情直到現在:JSP搜索表格
<form onsubmit="location.href='news.do?action=Search&search_string=${search}'" >
Search: <input type="text" name="search">
</form>
如果你想提交您的形式爲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
<%
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>
謝謝,沒有的伎倆! – user3531055