在開發web應用程序時,通常需要同時使用3種技術,並分別承擔不同的職責。jsp一般來編寫用戶界面層的信息顯示,充當視圖層的角色(簡稱:V);servlet需要來扮演任務的執行者,一般充當控制層的角色(簡稱:C);Javabean主要實現業務邏輯的處理,充當模型層的角色(簡稱:M)。這些分工就如同流水線一般,不同的人有不同的任務,承擔不同的責任。通過這三種技術的組合實現不同組件功能分工協作,將一個系統的功能分爲3種不同類型的組件,這種技術通常稱爲MVC模式。
目錄
五、基於MVC技術+Dao技術的學生信息管理系統的設計(Dao技術是一種數據庫連接技術)
一、jsp技術
jsp是一種運行在服務器端的腳本語言,它是用來開發動態網頁的技術,是Java web程序開發的重要技術。與jsp相反的就是HTML,它是一種靜態網絡開發技術。
如果你已經知道了MVC開發模式,想來你應該也已經知道了jsp技術。
如果你不知道的話,那麼你可以到菜鳥教程網站或者w3school網站去學習,通過百度就可以查到,這些網站講的都比較好。
二、Javabean技術
Javaweb是用Java語言編寫的、遵循一定標準的類,他封裝了數據和業務邏輯,完成數據封裝和數據處理等功能。
詳情可見:
java web--javabean技術:https://blog.csdn.net/qq_43238335/article/details/105701359
三、servlet技術
Servlet技術是一種Java語言編寫的服務器端程序,是由服務器端調用和執行的、按照servlet自身規範編寫的Java。servlet可以處理客戶端傳來的http請求,並返回一個響應。
詳情可見:
java web--Servlet技術(一):https://blog.csdn.net/qq_43238335/article/details/105964695
java web--Servlet技術(二):https://blog.csdn.net/qq_43238335/article/details/106138427
四、簡單的MVC開發模式介紹
輸入圓的半徑,求得圓的周長和麪積
簡單的分爲四個部分:兩個jsp文件、一個Javabean文件、一個servlet文件。
jsp完成數據的獲取和顯示,Javabean完成業務邏輯的處理,servlet完成具體的功能。
1.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>
</head>
<body>
<p>請輸入圓的半徑</p>
<hr>
<form action="../a02b" method="post">
<table>
<tr><td>圓的半徑:</td><td><input name="radius"></td></tr>
<tr><td><input type="submit" value="確認"></td><td><input type="reset" value="取消"></td></tr>
</table>
</form>
</body>
</html>
2.javabean業務邏輯
package aaa;
public class a02a {
private double radius;
public a02a() {
super();
// TODO Auto-generated constructor stub
}
public a02a(double radius) {
super();
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double mj()
{
return Math.PI*radius*radius;
}
public double zc()
{
return Math.PI*2*radius;
}
}
3.servlet 具體的完成功能,計算出圓的周長和麪積
package aaa;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class a02b
*/
@WebServlet("/a02b")
public class a02b extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public a02b() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request,response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String number=request.getParameter("radius");
double r=Double.parseDouble(number);
a02a aa=new a02a(r);
double mj=aa.mj();
double zc=aa.zc();
request.setAttribute("mj", mj);
request.setAttribute("zc", zc);
request.getRequestDispatcher("/a02/a02d.jsp").forward(request, response);
}
}
4.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>
</head>
<body>
<%
out.println("面積爲 "+request.getAttribute("mj"));
out.println("<br>");
out.println("周長爲 "+request.getAttribute("zc"));
%>
</body>
</html>
五、基於MVC技術+Dao技術的學生信息管理系統的設計(Dao技術是一種數據庫連接技術)
我通過Dao技術連接的是MySQL的數據庫。
以下是管理系統的流程和結構(僅爲查詢模塊,其餘模塊與查詢模塊相同)
1.javabean部分
//User.java文件
package bean1;
public class User {
private int id;
private String name;
private String sex;
private int age;
private double weight;
private double height;
public User() {
super();
// TODO Auto-generated constructor stub
}
public User(int id, String name, String sex, int age, double weight, double height) {
super();
this.id = id;
this.name = name;
this.sex = sex;
this.age = age;
this.weight = weight;
this.height = height;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
}
2.Dao部分
//db.properties文件
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/aaa?useUnicode=true&characterEncoding=UTF-8
user=root
password=2411030483
//JdbcUtil.java文件
package bean1;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class JdbcUtil {
private static String driver;
private static String url;
private static String user;
private static String password;
private static Properties pr=new Properties();
public JdbcUtil(){
super();
}
static
{
try {
pr.load(JdbcUtil.class.getClassLoader().getResourceAsStream("db.properties"));
driver=pr.getProperty("driver");
url=pr.getProperty("url");
user=pr.getProperty("user");
password=pr.getProperty("password");
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException
{
return DriverManager.getConnection(url,user,password);
}
public static void free(Connection conn,Statement st,ResultSet rs) throws Exception
{
if(conn!=null){conn.close();}
if(st!=null){st.close();}
if(rs!=null){rs.close();}
}
}
//UserDao.java文件
package bean1;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class UserDao {
public int add(User user)throws Exception
{
Connection conn=(Connection) JdbcUtil.getConnection();
String sql="insert into biao1(id,name,sex,age,weight,height) values(?,?,?,?,?,?);";
PreparedStatement pstmt=(PreparedStatement) conn.prepareStatement(sql);
pstmt.setInt(1,user.getId());//將第一個佔位符賦值
pstmt.setString(2,user.getName());
pstmt.setString(3,user.getSex());
pstmt.setInt(4,user.getAge());
pstmt.setDouble(5,user.getWeight());
pstmt.setDouble(6,user.getHeight());
int n=pstmt.executeUpdate();
JdbcUtil.free(conn,pstmt,null);
return n;
}
public int update(User user)throws Exception
{
Connection conn=(Connection) JdbcUtil.getConnection();
String sql="update biao1 set id=?,name=?,sex=?,age=?,weight=?,height=? where name=? and sex=?";
PreparedStatement pstmt=(PreparedStatement) conn.prepareStatement(sql);
pstmt.setInt(1,user.getId());//將第一個佔位符賦值
pstmt.setString(2,user.getName());
pstmt.setString(3,user.getSex());
pstmt.setInt(4,user.getAge());
pstmt.setDouble(5,user.getWeight());
pstmt.setDouble(6,user.getHeight());
pstmt.setString(7,user.getName());
pstmt.setString(8,user.getSex());
int n=pstmt.executeUpdate();
JdbcUtil.free(conn,pstmt,null);
return n;
}
public int delete(String name,String sex,double weight1,double weight2)throws Exception
{
Connection conn=(Connection) JdbcUtil.getConnection();
String sql="delete from biao1 where name=?,sex=?,weight>=? and weight<=?;";
PreparedStatement pstmt=(PreparedStatement) conn.prepareStatement(sql);
pstmt.setString(1,name);
pstmt.setString(2,sex);
pstmt.setDouble(3,weight1);
pstmt.setDouble(4,weight2);
int n=pstmt.executeUpdate();
JdbcUtil.free(conn,pstmt,null);
return n;
}
public List<User> findUserById(double weight1,double weight2)throws Exception
{
Connection conn=(Connection) JdbcUtil.getConnection();
User user=null;
List<User> userList=new ArrayList<User>();
String sql = "select id,name,sex,age,weight,height from biao1 where weight>=? and weight<=?;";//寫出對數據庫的操作語句,?表示佔位符
PreparedStatement pstmt=(PreparedStatement) conn.prepareStatement(sql);
pstmt.setDouble(1,weight1);
pstmt.setDouble(2,weight2);
ResultSet rs=pstmt.executeQuery();
while(rs.next())
{
user=new User();
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setSex(rs.getString("sex"));
user.setAge(rs.getInt("age"));
user.setWeight(rs.getDouble("weight"));
user.setHeight(rs.getDouble("height"));
userList.add(user);
}
JdbcUtil.free(conn,pstmt,rs);
return userList;
}
public List<User> QueryAll() throws Exception
{
Connection conn=(Connection) JdbcUtil.getConnection();
User user=null;
List<User> userList=new ArrayList<User>();
String sql="select * from biao1";
PreparedStatement pstmt=(PreparedStatement) conn.prepareStatement(sql);
ResultSet rs=pstmt.executeQuery();
while(rs.next())
{
user=new User();
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setSex(rs.getString("sex"));
user.setAge(rs.getInt("age"));
user.setWeight(rs.getDouble("weight"));
user.setHeight(rs.getDouble("height"));
userList.add(user);
}
JdbcUtil.free(conn,pstmt,rs);
return userList;
}
}
3.servlet部分
//a01a_delete2.java文件
package bean1;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class a01a_delete2
*/
@WebServlet("/a01a_delete2")
public class a01a_delete2 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public a01a_delete2() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
String name=request.getParameter("name");
String sex=request.getParameter("sex");
String ww1=request.getParameter("w1");
String ww2=request.getParameter("w2");
double weight1=Double.parseDouble(ww1);
double weight2=Double.parseDouble(ww2);
UserDao dao=new UserDao();
try {
int n=dao.delete(name, sex, weight1, weight2);
request.setAttribute("number", n);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.getRequestDispatcher("/a01a_delete/a01a_delete3.jsp").forward(request,response);
}
}
//a01a_insert2.jsp文件
package bean1;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class a01a_insert2
*/
@WebServlet("/a01a_insert2")
public class a01a_insert2 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public a01a_insert2() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
String id=request.getParameter("id_in");
String name=request.getParameter("name_in");
String sex=request.getParameter("sex_in");
String age=request.getParameter("age_in");
String weight=request.getParameter("weight_in");
String height=request.getParameter("height_in");//通過表單獲取數據
int id2=Integer.parseInt(id);//將數據轉換爲相應類型
int age2=Integer.parseInt(age);
double weight2=Double.parseDouble(weight);
double height2=Double.parseDouble(height);
User user=new User(id2,name,sex,age2,weight2,height2);
UserDao dao=new UserDao();
try {
int n=dao.add(user);
request.setAttribute("number", n);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.getRequestDispatcher("/a01a_insert/a01a_insert3.jsp").forward(request,response);
}
}
//a01a_select2.java文件
package bean1;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class a01a_select2
*/
@WebServlet("/a01a_select2")
public class a01a_select2 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public a01a_select2() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
String weight1 = request.getParameter("weight1");//通過表單獲取數據
String weight2 = request.getParameter("weight2");
double wt1 = Double.parseDouble(weight1);
double wt2 = Double.parseDouble(weight2);//將數據轉換爲相應類型
UserDao dao=new UserDao();
try {
List<User> user=dao.findUserById(wt1, wt2);
request.setAttribute("list", user);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.getRequestDispatcher("/a01a_select/a01a_select3.jsp").forward(request,response);
}
}
//a01a_update.java文件
package bean1;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class a01a_update2
*/
@WebServlet("/a01a_update2")
public class a01a_update2 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public a01a_update2() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
int id2=Integer.parseInt(request.getParameter("id"));
String name2=request.getParameter("name");
String sex2=request.getParameter("sex");
int age2=Integer.parseInt(request.getParameter("age"));
double weight2=Double.parseDouble(request.getParameter("weight"));
double height2=Double.parseDouble(request.getParameter("height"));
UserDao dao=new UserDao();
User user=new User(id2,name2,sex2,age2,weight2,height2);
try {
int n=dao.update(user);
request.setAttribute("number", n);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.getRequestDispatcher("/a01a_update/a01a_update3.jsp").forward(request,response);
}
}
4.jsp部分
<!-- a01a_delete1.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>
</head>
<body>
<p>請寫入刪除信息</p>
<hr>
<form action="../a01a_delete2" method="post"><%//創建表單傳輸數據 %>
姓名: <input type="text" name="name"><br><br>
性別:
男<input type="radio" name="sex" value="男">
女<input type="radio" name="sex" value="女"><br><br>
體重範圍:<p>
最低體重: <input type="text" name="w1"><br><br>
最高體重: <input type="text" name="w2"><br><br>
<input type="submit" value="確認">
<input type="reset" value="取消">
</form><br>
</body>
</html>
<!-- a01a_delete3.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>
</head>
<body>
<p>刪除界面</p>
<hr>
<%
String a=request.getAttribute("number").toString();
int aa=Integer.parseInt(a);
if(aa>0) out.println("刪除成功");
else out.println("刪除失敗");
%>
</body>
</html>
<!-- a01a_insert1.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>
</head>
<body>
<p>請寫入插入信息</p>
<hr>
<form action="../a01a_insert2" method="post"><%//創建表單傳輸數據 %>
序號: <input type="text" name="id_in"><br><br>
姓名: <input type="text" name="name_in"><br><br>
性別: <input type="text" name="sex_in"><br><br>
年齡: <input type="text" name="age_in"><br><br>
體重: <input type="text" name="weight_in"><br><br>
身高: <input type="text" name="height_in"><br><br>
<input type="submit" value="確認">
<input type="reset" value="取消">
</form><br>
</body>
</html>
<!-- a01a_insert3.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>
</head>
<body>
<p>插入界面</p>
<hr>
<%
String a=request.getAttribute("number").toString();
int aa=Integer.parseInt(a);
if(aa>0) out.println("插入成功");
else out.println("插入失敗");
%>
</body>
</html>
<!-- a01a_select1.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>
</head>
<body>
<form action="../a01a_select2" method="post"><%//創建表單傳輸數據 %>
<p>請選擇想要查詢的分數範圍</p>
<hr>
最低體重: <input type="text" name="weight1"><br><br>
最高體重: <input type="text" name="weight2"><br><br>
<input type="submit" value="提交">
<input type="reset" value="取消">
</form><br>
</body>
</html>
<!-- a01a_select2.jsp文件 -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.List"%>
<%@ page import="bean1.a01a_select2"%>
<%@ page import="bean1.User"%>
<!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>
</head>
<body>
<p>查詢頁面</p>
<hr/>
<table>
<tr>
<td>學號</td>
<td>姓名</td>
<td>性別</td>
<td>年齡</td>
<td>體重</td>
<td>身高</td>
</tr>
<%List<User> list2=(List<User>)(request.getAttribute("list"));
for(int i=0;i<list2.size();i++)
{
User u=list2.get(i);
%>
<tr>
<td><%=u.getId()%></td>
<td><%=u.getName()%></td>
<td><%=u.getSex()%></td>
<td><%=u.getAge()%></td>
<td><%=u.getHeight()%></td>
<td><%=u.getHeight()%></td>
</tr>
<%
}
%>
</table>
</body>
</html>
<!-- a01a_update1.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>
</head>
<body>
<p>請寫入修改信息</p>
<hr>
<form action="../a01a_update2" method="post">
<table>
<tr>
<td>學號</td>
<td><input type="text" name="id" ></td>
</tr>
<tr>
<td>姓名</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>性別</td>
<td><input type="text" name="sex"></td>
</tr>
<tr>
<td>年齡</td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td>體重</td>
<td><input type="text" name="weight"></td>
</tr>
<tr>
<td>身高</td>
<td><input type="text" name="height"></td>
</tr>
<tr align="center">
<td><input type="submit" value="確認"></td>
<td><input type="reset" value="取消"></td>
</tr>
</table>
</form>
</body>
</html>
<!-- a01a_update2.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>
</head>
<body>
<p>更新界面</p>
<hr>
<%
String a=request.getAttribute("number").toString();
int aa=Integer.parseInt(a);
if(aa>0) out.println("更新成功");
else out.println("更新失敗");
%>
</body>
</html>
5.管理頁面
<%@ 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>
</head>
<frameset rows="80,*">
<frame src="indextitle.jsp" scrolling="no">
<frameset cols="140,*">
<frame src="indexleft.jsp" scrolling="no">
<frame src="indexright.jsp" name="right" scrolling="no">
</frameset>
</frameset>
</html>
<%@ 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>
</head>
<body>
<br><br><br><br>
<p><a href="../a01a_insert/a01a_insert1.jsp" target="right">添加學生</a></p>
<p><a href="../a01a_delete/a01a_delete1.jsp" target="right">按條件刪除學生</a></p>
<p><a href="../a01a_select/a01a_select1.jsp" target="right">按條件查詢學生</a></p>
<p><a href="../a01a_update/a01a_update1.jsp" target="right">按條件修改學生</a></p>
</body>
</html>
<%@ 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>Insert title here</title>
</head>
<body background="1.jpg">
</body>
</html>
<%@ 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>
</head>
<body>
<center><h1>學生身體體質信息管理系統</h1></center>
</body>
</html>
運行示例如下: