在使用表单的时候,有时需要从一个页面跳转到多个不同的页面。
比如:想要从1.jsp跳转到2.jsp和3.jsp。
我们可以这样写程序:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>跳转</title>
<script type="text/javascript">
//把表单的action改为2.jsp
function Two() {
document.form.action = "2.jsp";
document.form.submit();
}
//把表单的action改为3.jsp
function Three() {
document.form.action = "3.jsp";
document.form.submit();
}
</script>
</head>
<body>
<form action="" method="post" name="form">
<table width="300" border="1" align="center" bgcolor="#9AD3A4" bordercolor="red">
<tr><td align="center" colspan="2" >button跳转</td></tr>
<tr>
<td><input type="button" value="跳转到2.jsp" οnclick="Two()" class="botton"/></td>
<td><input type="button" value="跳转到3.jsp" οnclick="Three()" class="botton"/></td>
</tr>
</table>
</form>
</body>
</html>
我们就可以从1.jsp跳转到2.jsp或者是3.jsp从而实现一个页面访问多个页面。