update.jsp
<%@ page language=”java” import=”java.util.*” pageEncoding=”UTF-8″%>
<%@ page import=”java.sql.*”%>
The < %
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
% >
<! DOCTYPE HTML PUBLIC “-//W3C// HTML 4.01 Transitional//EN”>
<html>
<head>
<base href=”<%=basePath%>”>
<title> Student information </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;
var major = document.forms[0].major.value;
if(id <= 0){
Alert (” Student id cannot be empty, please enter student ID!” );
return false;
}
else if(name.length <= 0){
Alert (” Name cannot be empty, please enter name!” );
return false;
}
else if(age <= 0){
Alert (” Please enter legal age!” );
return false;
}
else if(major.length <= 0){
Alert (” Major cannot be empty, please enter major!” );
return false;
}
else{
return true;
}
//document.getElementById(“form”).submit();
}
function checkName(sName)
{
return “Li Wang Zhang Liuchen Yang zhao Huang Zhou Wu Xu Sun Hu Zhu Gaolin what guo Ma Luoliang Song Zheng xie han tang in dong feng deng Xu Fu Xiao Cheng cao yuan shen Zeng Peng Lv Su Lou Jiang Cai jardine wei xue ye yan Yu Pandu Dai Xia clock Wang Tian ren Jiang Fan stones tan yao liao Zou Xiong gold Hao Kong white Cui Kang Qiu Qin MAO lu jiang shi Gu Hou Shao Menglong ten thousand section of the chapter Shang Yinli easy Chang Wuqiao, lai Gong Wenpang FanLan reviews Yin hong ZhaiAnYan NiYan cattle temperature LuJiYu ZhangLu Ge Wu Wei Shen Yu Bi Nie Cong Jiao Xiang Liu Xing Lu Yue Qi Yan Mei Mo Zhuang Xin Guan Zhu Zuo Tu Gu Qi Qi Shi Shu Geng Mou Bu Lu Zhan Miao Ling Fei Ji Jin Sheng Tong Ou Zhen Xiang Qu Cheng You Yang Pei Xi Wei Cha Qu Bao Wei Tan Huo Weng Sui Zhi Gan Jing Bo Dan Bao Si Bai Ning Ke Ruan GUI Min Ouyang Xie Qiang Chai Hua Che Ran Fang “.
}
</script>
</head>
<body background=”pic/background.jpg”>
The < %
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/jsp”;
String user = “root”;
String password = “root”;
conn = DriverManager.getConnection(url,user,password);
stat = conn.createStatement();
rs = stat.executeQuery(“select * from student where id=” + id + “”);
% >
<br>
<h2> Student information </h2> < HR >
<br>
<h3> The student information to be modified is as follows </h3>
<table width=”450″ border=”100″ cellSpacing=1 style=”font-size:15pt; border:dashed 1pt”>
<tr>
< td > student id < / td >
Name of the < td > < / td >
Age < td > < / td >
Gender < td > < / td >
< td > < / td >
</tr>
The < %
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(“gender”) + “</td>”);
out.print(“<td>” + rs.getString(“major”) + “</td>”);
out.print(“</tr>”);
% >
</table>
<br>
<br>
<h3> Change student information to: </h3>
<form action=”updateShow.jsp” method=”post” onSubmit=”return validate()”>
< h4 > student id: < input type = “text” name = “id” value = “< % = rs. Get int (” id”) % > “title =” student id cannot be changed “readonly =” readonly “> < / input > < br > < / h4 >
<h4> name: <input type=”text” name=”name” title=” name must not be empty “></input><br></h4>
< h4 > age: < input type = “text” name = “age” title = “age can not be empty” > < / input > < br > < / h4 >
<h4> Gender: <input type=”radio” name=”gender” value=” male “> male
<input type=”radio” name=”gender” value=” female “> female <br></h4>
<h4> professional: <input type=”text” name=”major” title=” professional “></input><br></h4>
< form type=”submit” value=” submit” />
</form>
<br>
<h3><a href= addstuinfo.jsp > Return to add information page </a></h3>
<a href= showinfo.jsp ></ a></h3>
The < %
}
% >
The < %
if(rs ! = null)
{
rs.close();
rs = null;
}
if(stat ! = null)
{
stat.close();
stat = null;
}
if(conn ! = null)
{
conn.close();
conn = null;
}
% >
</body>
</html>
updateShow.jsp
<%@ page language=”java” import=”java.util.*” pageEncoding=”UTF-8″%>
<%@ page import=”java.sql.*”%>
The < %
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
% >
<! DOCTYPE HTML PUBLIC “-//W3C// HTML 4.01 Transitional//EN”>
<html>
<head>
<base href=”<%=basePath%>”>
<title> Student information </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;
var major = document.forms[0].major.value;
if(id <= 0){
Alert (” Student id cannot be empty, please enter student ID!” );
return false;
}
else if(name.length <= 0){
Alert (” Name cannot be empty, please enter name!” );
return false;
}
else if(age <= 0){
Alert (” Please enter legal age!” );
return false;
}
else if(major.length <= 0){
Alert (” Major cannot be empty, please enter major!” );
return false;
}
else{
return true;
}
//document.getElementById(“form”).submit();
}
function checkName(sName)
{
return “Li Wang Zhang Liuchen Yang zhao Huang Zhou Wu Xu Sun Hu Zhu Gaolin what guo Ma Luoliang Song Zheng xie han tang in dong feng deng Xu Fu Xiao Cheng cao yuan shen Zeng Peng Lv Su Lou Jiang Cai jardine wei xue ye yan Yu Pandu Dai Xia clock Wang Tian ren Jiang Fan stones tan yao liao Zou Xiong gold Hao Kong white Cui Kang Qiu Qin MAO lu jiang shi Gu Hou Shao Menglong ten thousand section of the chapter Shang Yinli easy Chang Wuqiao, lai Gong Wenpang FanLan reviews Yin hong ZhaiAnYan NiYan cattle temperature LuJiYu ZhangLu Ge Wu Wei Shen Yu Bi Nie Cong Jiao Xiang Liu Xing Lu Yue Qi Yan Mei Mo Zhuang Xin Guan Zhu Zuo Tu Gu Qi Qi Shi Shu Geng Mou Bu Lu Zhan Miao Ling Fei Ji Jin Sheng Tong Ou Zhen Xiang Qu Cheng You Yang Pei Xi Wei Cha Qu Bao Wei Tan Huo Weng Sui Zhi Gan Jing Bo Dan Bao Si Bai Ning Ke Ruan GUI Min Ouyang Xie Qiang Chai Hua Che Ran Fang “.
}
</script>
</head>
<body background=”pic/background.jpg”>
The < %
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/jsp”;
String user = “root”;
String password = “root”;
conn = DriverManager.getConnection(url,user,password);
stat = conn.createStatement();
rs = stat.executeQuery(“select * from student where id=” + id + “”);
% >
<br>
<h2> Student information </h2> < HR >
<br>
<h3> The student information to be modified is as follows </h3>
<table width=”450″ border=”100″ cellSpacing=1 style=”font-size:15pt; border:dashed 1pt”>
<tr>
< td > student id < / td >
Name of the < td > < / td >
Age < td > < / td >
Gender < td > < / td >
< td > < / td >
</tr>
The < %
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(“gender”) + “</td>”);
out.print(“<td>” + rs.getString(“major”) + “</td>”);
out.print(“</tr>”);
% >
</table>
<br>
<br>
<h3> Change student information to: </h3>
<form action=”updateShow.jsp” method=”post” onSubmit=”return validate()”>
< h4 > student id: < input type = “text” name = “id” value = “< % = rs. Get int (” id”) % > “title =” student id cannot be changed “readonly =” readonly “> < / input > < br > < / h4 >
<h4> name: <input type=”text” name=”name” title=” name must not be empty “></input><br></h4>
< h4 > age: < input type = “text” name = “age” title = “age can not be empty” > < / input > < br > < / h4 >
<h4> Gender: <input type=”radio” name=”gender” value=” male “> male
<input type=”radio” name=”gender” value=” female “> female <br></h4>
<h4> professional: <input type=”text” name=”major” title=” professional “></input><br></h4>
< form type=”submit” value=” submit” />
</form>
<br>
<h3><a href= addstuinfo.jsp > Return to add information page </a></h3>
<a href= showinfo.jsp ></ a></h3>
The < %
}
% >
The < %
if(rs ! = null)
{
rs.close();
rs = null;
}
if(stat ! = null)
{
stat.close();
stat = null;
}
if(conn ! = null)
{
conn.close();
conn = null;
}
% >
</body>
</html>
The entire structure is as follows:
p24
Now for the final step.
We need to download a zip file to drive mysql-conn-java-5.1.20
\
Download the second and save.
Unzip and find a JAR file that looks like this
Copy to the lib folder in web-INF under Normal and you’re done
Open the bin folder of the Tomcat folder
Go to startup.bat and double-click to open it
Open a browser
In the address bar enter * http://localhost:808/normal/ *
\
The resulting interface is as above, and then familiarize yourself with it.
Building Lord QQ: 496056171