您的位置:首页 > Web前端 > JavaScript

var写在js中

2016-10-03 23:28 106 查看
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ page import="java.sql.*"%>

<%
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 'update.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 type="text/javascript">
function validate() {
var id = document.forms[0].id.value;
var name = document.forms[0].name.value;
var age = document.forms[0].age.value;
if (id <= 0) {
alert("validate----学号不能为空,请输入学号!");
return false;
} else if (name.length <= 0) {
alert("validate----姓名不能为空,请输入姓名!");
return false;
} else if (age <= 0) {
alert("validate----请输入合法年龄!");
return false;
}

else {
return true;
}
//document.getElementById("form").submit();
}

function checkName() {
var sName = document.forms[0].name.value;
alert("----"+sName+"--"); 
alert("调用checkname函数");
if ("李王张刘陈杨赵黄周吴徐孙胡朱高林何郭马罗梁宋郑谢韩唐冯于董萧程曹袁邓许傅沈曾彭吕苏卢蒋蔡贾丁魏薛叶阎余潘杜戴夏钟汪田任姜范方石姚谭廖邹熊金陆郝孔白崔康毛邱秦江史顾侯邵孟龙万段章钱汤尹黎易常武乔贺赖龚文庞樊兰殷施陶洪翟安颜倪严牛温芦季俞章鲁葛伍韦申尤毕聂丛焦向柳邢路岳齐沿梅莫庄辛管祝左涂谷祁时舒耿牟卜路詹关苗凌费纪靳盛童欧甄项曲成游阳裴席卫查屈鲍位覃霍翁隋植甘景薄单包司柏宁柯阮桂闵欧阳解强柴华车冉房"
.indexOf(sName.charAt(0)) != -1) {
alert("是一个中国姓氏");
}
}

</script>

</head>

<body>
<%
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
Connection conn = null;
Statement stat = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/dbjsp";
String user = "root";
String password = "123456";
conn = DriverManager.getConnection(url, user, password);
stat = conn.createStatement();
rs = stat.executeQuery("select * from person where id=" + id + "");
%>
<br>
<h2>学生信息</h2>
<hr>
<br>
<h3>要修改的学生信息如下</h3>
<table width="450" border="100" cellSpacing=1
style="font-size: 15pt; border: dashed 1pt">
<tr>
<td>学号</td>
<td>姓名</td>
<td>年龄</td>
<td>性别</td>
</tr>
<%
while (rs.next()) {
out.print("<tr>");
out.print("<td>" + rs.getInt("id") + "</td>");
out.print("<td>" + rs.getString("name") + "</td>");
out.print("<td>" + rs.getInt("age") + "</td>");
out.print("<td>" + rs.getString("sex") + "</td>");
out.print("</tr>");
%>
</table>

<br>
<br>
<h3>将学生信息更改为:</h3>
<form action="updateShow.jsp" method="post" onSubmit="checkName(),validate()"
onSubmit="">
<h4>
学号: <input type="text" name="id" value="<%=rs.getInt("id")%>"
title="学号不能改变" readonly="readonly"></input> <br>
</h4>
<h4>
姓名: <input type="text" name="name" title="姓名不能为空"></input> <br>
</h4>
<h4>
年龄: <input type="text" name="age" title="年龄不能为空"></input> <br>
</h4>
<h4>
性别: <input type="radio" name="sex" value="男"> 男 <input
type="radio" name="sex" value="女"> 女 <br>
</h4>
<input type="submit" value="修改" />
</form>

<br>
<h3>
<a href=addStuInfo.jsp>返回添加信息页面</a>
</h3>
<h3>
<a href=showInfo.jsp>返回信息查询页
4000
面</a>
</h3>
<%
}
%>
<%
if (rs != null) {
rs.close();
rs = null;
}
if (stat != null) {
stat.close();
stat = null;
}
if (conn != null) {
conn.close();
conn = null;
}
%>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: