📄 modify.jsp
字号:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<jsp:directive.page import="student.Student"/>
<jsp:useBean id="show" scope="request" class="student.StudentDao">
<jsp:setProperty name="show" property="*" />
</jsp:useBean>
<%
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 'modify.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">
-->
<script language="javascript" type="text/javascript">
function check(str) //检查是否有空格
{
var is=false; //不能用boolean定义??????
var i=str.length;
var k = 0;
while (k<i)
{
if(str.charAt(k)==" ")
is=true;
k++;
}
return is;
}
function checkinfoName()
{
var str = document.getElementById("studentName").value;
if(str.length<=0||str.length>10)
{
alert("请输入姓名(<10个字符)!");
return false;
}
if(check(str))
{
alert("姓名不能包含空格");
return false;
}
return true;
}
function checkinfoAge()
{
var str = document.getElementById("studentAge").value;
var patrn=/^[0-9]{1,20}$/;
if(str.length<=0||str.length>20)
{
alert("请输入年龄!");
return false;
}
if (!patrn.exec(str))
{
alert("请输入正整数!");
return false;
}
return true;
}
function checkinfoNum()
{
var str = document.getElementById("studentNum").value;
if(str.length<=0||str.length>10)
{
alert("请输入学号(<10个字符)!");
return false;
}
if(check(str))
{
alert("学号不能包含空格");
return false;
}
return true;
}
function checkinfoClass()
{
var str = document.getElementById("studentClass").value;
if(str.length<=0||str.length>20)
{
alert("请输入班级(<20个字符)!");
return false;
}
if(check(str))
{
alert("班级不能包含空格");
return false;
}
return true;
}
function checkinfo()
{
if(checkinfoName()&&checkinfoAge()&&checkinfoNum()&&checkinfoClass())
return true;
else return false;
}
</script>
</head>
<body>
<center>
<br><br>
<c:choose>
<c:when test="${student.studentName!=null}"> <!-- 注意这里如何取值的 -->
<form method="POST" action="student/modify" onsubmit="return checkinfo()">
</c:when>
<c:otherwise>
<form method="POST" action="student/add" onsubmit="return checkinfo()">
</c:otherwise>
</c:choose>
姓 名:<input type="TEXT" name="name" value="${student.studentName}" id="studentName" />
<!--字符串的话,value=后面要加双引号,若不加,字符串有空格的话显示就会有问题-->
<br><br>
年 龄:<input type="TEXT" name="age" value="${student.studentAge}" id="studentAge" />
<br><br>
学 号:<input type="TEXT" name="num" value="${student.studentNum}" id="studentNum" />
<br><br>
班 级:<input type="TEXT" name="class" value="${student.studentClass}" id="studentClass"/>
<br><br>
<c:choose>
<c:when test="${student.studentName!=null}"> <!-- 注意这里如何取值的 -->
<input type="submit" style="width:80px;height:30px" value="修 改" />
</c:when>
<c:otherwise>
<input type="submit" style="width:80px;height:30px" value="添 加" />
</c:otherwise>
</c:choose>
</form>
</center>
<center>
<input type=button style="width:80px;height:30px" value="返 回"
onClick="location.href='http://127.0.0.1:8080/StudentDBMS/student/studentDB.jsp'">
</center>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -