利用函数实现跳转jsp页面,实现相关功能
创建主页面index.jsp,里面编写js函数代码,实现点击跳转到相应的jsp页面,代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="xianshi.jsp" method="post" name="form1">
学号:<input type="text" name="id"><br>
姓名:<input type="text" name="name"><br>
性别:<input type="text" name="sex"><br><br><br><br>
<input type="button" name="add" value="添加" onClick="skip('add.jsp')">
<input type="button" name="delete" value="删除" onClick="skip('delete.jsp')">
<input type="button" name="alter" value="修改" onClick="skip('alter.jsp')">
<input type="button" name="query" value="查询" onClick="skip('query.jsp')">
</form>
<script type="text/javascript">
//编写skip方法
function skip(a){
form1.action=a;
form1.submit();
}
</script>
</body>
</html>
结果:
点击添加按钮,跳转到add.jsp页面:
点击删除按钮,跳转到delete.jsp页面:
点击修改按钮,跳转到alter.jsp页面:
点击查询按钮,跳转到query.jsp页面: