表单组件不仅用于制作表单还可以跳转指定页面
JSP中提交表单的同时页面跳转是通过servlet控制的。
RequestDispatcher.forward()
是在服务器端起作用,当使用forward()时,Servlet engine传递HTTP请求从当前的Servlet or JSP到另外一个Servlet,JSP 或普通HTML文件,也即你的form提交至a.jsp,在a.jsp用到了forward()重定向至b.jsp,此时form提交的所有信息在 b.jsp都可以获得,参数自动传递. 但forward()无法重定向至有frame的jsp文件,可以重定向至有frame的html文件,同时forward()无法在后面带参数传递,比如servlet?name=frank,这样不行,可以程序内通过response.setAttribute("name",name)来传至下一个页面。
重定向后浏览器地址栏URL不变。
例:在servlet中进行重定向
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html; charset=gb2312");
ServletContext sc = getServletContext();
RequestDispatcher rd = null;
rd = sc.getRequestDispatcher("/index.jsp"); //定向的页面
rd.forward(request, response);
}
用表单实现页面跳转用跳转菜单就可以实现:
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<!--以上这里是实现跳转的脚本,在dreamweaver中选跳转菜单控件,这个代码就会自动生成-->
<form name="form2" id="form2">
<select name="menu1" onchange="MM_jumpMenu('parent',this,0)">
<option>请选择</option>
<option value=" "> </option>
</select>
</form>