基于Struts2+Hibernate5的学生信息管理系统

本项目使用Struts2+Hibernate5为开发环境,通过对学生信息进行增删改查等操作。
项目使用MySQL数据库,数据库名为student,表为stuinfo,表的字段如下所示:
基于Struts2+Hibernate5的学生信息管理系统_第1张图片
项目的文件结构:
基于Struts2+Hibernate5的学生信息管理系统_第2张图片
HibernateSessionFactory.java

package addHibernateFile;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateSessionFactory {
	private static SessionFactory sessionFactory;
	public static Session getSession() {
		return getSessionFactory().openSession();
	}
	public static SessionFactory getSessionFactory() {
		if(sessionFactory==null||sessionFactory.isClosed()) {
			sessionFactory=new Configuration().configure().buildSessionFactory();
		}
		return sessionFactory;
	}
}

StudentDao.java

package Dao;
import addHibernateFile.HibernateSessionFactory;
import PO.Stuinfo;
import java.util.List;
import javax.swing.JOptionPane;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;

public class StudentDao {
	private Transaction transaction;
	private Session session;
	private Query query;
	
	public StudentDao() {
		
	}

	public boolean saveInfo(Stuinfo info) {
		try {
			session=HibernateSessionFactory.getSession();
			transaction=session.beginTransaction();
			session.save(info);
			transaction.commit();
			session.close();
			return true;
		}catch (Exception e) {
			// TODO: handle exception
			message("saveInfo.error:"+e);
			e.printStackTrace();
			return false;
		}
	}
	
	public List findInfo(String type,Object value) {
		session=HibernateSessionFactory.getSession();
		try {
			transaction=session.beginTransaction();
			//HQL语句
			String queryString="from Stuinfo as model where model."+type+"=?";
			query=session.createQuery(queryString);
			query.setParameter(0, value);
			List list=query.list();
			transaction.commit();
			session.close();
			return list;
		}catch (Exception e) {
			// TODO: handle exception
			message("findInfo.error:"+e);
			e.printStackTrace();
			return null;
		}
	}
	
	public List findAllInfo() {
		session=HibernateSessionFactory.getSession();
		try {
			transaction=session.beginTransaction();
			//HQL语句
			String queryString="from Stuinfo";
			query=session.createQuery(queryString);
			List list=query.list();
			transaction.commit();
			session.close();
			return list;
		}catch (Exception e) {
			// TODO: handle exception
			message("findInfo.error:"+e);
			e.printStackTrace();
			return null;
		}
	}
	
	public boolean deleteInfo(String id) {
		try {
			session=HibernateSessionFactory.getSession();
			transaction=session.beginTransaction();
			Stuinfo info=new Stuinfo();
			info=(Stuinfo)session.get(Stuinfo.class, id);
			session.delete(info);
			transaction.commit();
			return true;
		}catch (Exception e) {
			// TODO: handle exception
			message("deleteInfo.error:"+e);
			e.printStackTrace();
			return false;
		}
	}
	
	public boolean updateInfo(Stuinfo info) {
		try {
			session=HibernateSessionFactory.getSession();
			transaction=session.beginTransaction();
			session.update(info);
			transaction.commit();
			session.close();
			return true;
		}catch (Exception e) {
			// TODO: handle exception
			message("updateInfo.error:"+e);
			e.printStackTrace();
			return false;
		}
	}
	
	public void message(String mess) {
		int type=JOptionPane.YES_NO_OPTION;
		String title="提示信息";
		JOptionPane.showMessageDialog(null, mess,title,type);
	}
}

Stuinfo.java

package PO;



public class Stuinfo implements java.io.Serializable{
	private String id;
	private String name;
	private String sex;
	private int age;
	private float weight;
	public String getId() {
		return id;
	}
	public void setId(String 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 float getWeight() {
		return weight;
	}
	public void setWeight(float weight) {
		this.weight = weight;
	}
	
}

Stuinfo.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- 解析文件的DTD -->
<!DOCTYPE hibernate-mapping PUBLIC
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
	<!-- 映射文件的根目录 -->
	<hibernate-mapping>
		<class name="PO.Stuinfo" table="stuinfo" catalog="student">
			<id name="id" type="string">
				<column name="id" length="20"></column>
				<generator class="assigned"></generator>
			</id>
			<property name="name" type="string">
				<column name="name" length="20" not-null="true"></column>
			</property>
			<property name="sex" type="string">
				<column name="sex" length="5" not-null="true"></column>
			</property>
			<property name="age" type="int">
				<column name="age" not-null="true"></column>
			</property>
			<property name="weight" type="float">
				<column name="weight" precision="10" scale="0" not-null="true"></column>
			</property>
		</class>
	</hibernate-mapping>

AddMessageAction.java

package studentAction;
import Dao.StudentDao;
import PO.Stuinfo;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import javax.swing.JOptionPane;

import org.eclipse.jdt.internal.compiler.ast.ThisReference;

public class AddMessageAction extends ActionSupport{
	private String id;
	private String name;
	private String sex;
	private int age;
	private float weight;
	private String message="input";
	public String getId() {
		return id;
	}
	public void setId(String 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 float getWeight() {
		return weight;
	}
	public void setWeight(float weight) {
		this.weight = weight;
	}
	
	public void validate() {
		if(this.getId()==null||this.getId().length()==0) {
			addFieldError("id", "学号不允许为空!!!");
		}
		else {
			StudentDao dao=new StudentDao();
			List list=dao.findInfo("id", this.getId());
			if(!list.isEmpty()) {
				addFieldError("id", "学号已存在!!!");
			}
		}
		if(this.getName()==null||this.getName().length()==0){
			addFieldError("name", "姓名不允许为空!!!");
		}
		if(this.getAge()>130) {
			addFieldError("age", "请认真核实年龄!!!");
		}
		if(this.getWeight()>500) {
			addFieldError("weight", "请认真核实体重!!!");
		}
	}
	
	public  String execute() throws Exception{
		StudentDao dao=new StudentDao();
		boolean save=dao.saveInfo(info());
		if (save) {
			message=SUCCESS;
		}
		return message;
	}
			
	
	public Stuinfo info() {
		Stuinfo info=new Stuinfo();
		info.setId(this.getId());
		info.setName(this.getName());
		info.setSex(this.getSex());
		info.setAge(this.getAge());
		info.setWeight(this.getWeight());
		return info;
	}
	
	public void message(String mess) {
		int type=JOptionPane.YES_NO_OPTION;
		String title="提示信息";
		JOptionPane.showMessageDialog(null, mess,title,type);
	}
	
		
	
}

DeleteMessageAction.java

package studentAction;
import Dao.StudentDao;
import freemarker.template.utility.Execute;

import com.opensymphony.xwork2.ActionSupport;
import javax.swing.JOptionPane;

public class DeleteMessageAction extends ActionSupport{
	private String id;
	private String message;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	public void validate() {
		if(this.getId().equals("null")) {
			message("暂无学生信息!!!");
			addFieldError("id", "暂无学生信息!!!");
		}
	}
	
	public String execute() throws Exception{
		StudentDao dao=new StudentDao();
		boolean del=dao.deleteInfo(this.getId());
		if(del) {
			message=SUCCESS;
		}
		return message;
	}

	public void message(String mess) {
		int type=JOptionPane.YES_NO_OPTION;
		String title="提示信息";
		JOptionPane.showMessageDialog(null, mess,title,type);
	}
}

FindMessageAction.java

package studentAction;
import Dao.StudentDao;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.swing.JOptionPane;
import org.apache.struts2.ServletActionContext;
import org.eclipse.jdt.internal.compiler.ast.ThisReference;

public class FindMessageAction extends ActionSupport{
	private String id;
	private HttpServletRequest request;
	private String message="input";
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	public void validate() {
		if(this.getId().equals("null")) {
			message("暂无学生信息!!!");
			addFieldError("id", "暂无学生信息!!!");
		}
	}
	
	public String execute() throws Exception{
		request=ServletActionContext.getRequest();
		StudentDao dao=new StudentDao();
		List list=dao.findInfo("id", this.getId());
		request.getSession().setAttribute("oneInfo", list);
		message=SUCCESS;
		return message;
	}

	public void message(String mess) {
		int type=JOptionPane.YES_NO_OPTION;
		String title="提示信息";
		JOptionPane.showMessageDialog(null, mess,title,type);
	}
}

LookMessageAction.java

package studentAction;
import Dao.StudentDao;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;

public class LookMessageAction extends ActionSupport{
	private HttpServletRequest request;
	private String message="input";
	
	public String execute() throws Exception{
		request=ServletActionContext.getRequest();
		//实例化
		StudentDao dao=new StudentDao();
		//调用StudentDao类中的FindAllInfo()方法
		List list=dao.findAllInfo();
		//向session对象传值
		request.getSession().setAttribute("count", list.size());
		request.getSession().setAttribute("allInfo", list);
		message="success";
		return message;
	}
}

UpdateMessageAction.java

package studentAction;
import Dao.StudentDao;
import PO.Stuinfo;
import com.opensymphony.xwork2.ActionSupport;
import javax.swing.JOptionPane;

public class UpdateMessageAction extends ActionSupport{
	private String id;
	private String name;
	private String sex;
	private int age;
	private float weight;
	private String message="input";
	public String getId() {
		return id;
	}
	public void setId(String 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 float getWeight() {
		return weight;
	}
	public void setWeight(float weight) {
		this.weight = weight;
	}
	
	public void validate() {
		if(this.getName()==null||this.getName().length()==0) {
			addFieldError("name", "姓名不允许为空!!!");
		}
		if(this.getAge()>130) {
			addFieldError("age", "请认真核实年龄!!!");
		}
		if(this.getWeight()>500) {
			addFieldError("weight", "请认真核实体重!!!");
		}
	}

	public String execute() throws Exception{
		StudentDao dao=new StudentDao();
		boolean update=dao.updateInfo(info());
		if(update) {
			message=SUCCESS;
		}
		return message;
	}
	
	public Stuinfo info() {
		Stuinfo info=new Stuinfo();
		info.setId(this.getId());
		info.setName(this.getName());
		info.setSex(this.getSex());
		info.setAge(this.getAge());
		info.setWeight(this.getWeight());
		return info;
	}
	
	public void message(String mess) {
		int type=JOptionPane.YES_NO_OPTION;
		String title="提示信息";
		JOptionPane.showMessageDialog(null, mess,title,type);
	}
}

hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
	<!-- Hibernate配置文件的根元素,其他元素应在其中 -->
	<hibernate-configuration>
		<!-- 设置初始化Hibernate5参数的元素,其中指定HIbernate5初始化参数,
			表明以下的配置是针对session-factory配置,SessionFactory是Hibernate5中的一个接口
			这个接口主要负责保存Hibernate5的配置信息以及对Session的操作 -->
		<session-factory>
			<!-- 设置连接数据库所用的驱动 -->
			<property name="hibernate.connection.driver_class">
				com.mysql.jdbc.Driver
			</property>	
			<!-- 设置数据库连接使用的URL -->
			<property name="hibernate.connection.url">
				jdbc:mysql://127.0.0.1:3306/student
			</property>
			<!-- 设置数据库的用户名 -->
			<property name="hibernate.connection.username">root</property>
			<!-- 设置数据库的密码 -->
			<property name="hibernate.connection.password">hjw19990825</property>
			<!-- 设置数据库的方言,每种数据库都有对应的方言 -->
			<property name="hibernate.dialect">
				org.hibernate.dialect.MySQL5Dialect
			</property>
			<!-- 设置连接池中的最小连接数 -->
			<property name="hibernate.c3p0.min_size">10</property>
			<!-- 设置连接池中的最大连接数 -->
			<property name="hibernate.c3p0.max_size">50</property>
			<!-- 设置连接池中某个数据库访问超时时间,超时将被移除,即最大时间 -->
			<property name="hibernate.c3p0.timeout">120</property>
			<!-- 设置时间范围内检查所有连接的空闲时间并销毁超时的连接 -->
			<property name="hibernate.c3p0.idle_test_period">3000</property>
			<!-- 设置当连接池中的连接耗尽的时候,一次同时获取的连接数 -->
			<property name="acquireIncrement">5</property>
			<!-- 设置在从数据库获取新连接失败后重复尝试的次数 -->
			<property name="acquireRetryAttempts">30</property>
			<!-- 设置两次连接中间隔时间,单位为毫秒 -->
			<property name="acquireRettryDelay">1000</property>
			<!-- 连接关闭时默认将所有未提交的操作回滚 -->
			<property name="autoCommitOnClose">false</property>
			<!-- 设置session上下文,thread表示,当前thread中取到session保证是同一个session -->
			<property name="current_session_content_class">thread</property>
			<!-- 根据需要自动创建数据表 -->
			<property name="binernate.hbm2ddl.auto">update</property>
			<!-- 设置是否将Hibernate5发送给数据库的SQL语句,有助于迅速解决问题 -->
			<property name="hibernate.format_sql">true</property>
			<!-- 加入映射文件,可以加入多个映射文件 -->
			<mapping resource="PO/Stuinfo.hbm.xml"/>
		</session-factory>
	</hibernate-configuration>

struts.xml

<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
	"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
	<include file="example.xml"></include>
	<package name="default" extends="struts-default">
	
		<action name="lookMessageAction" class="studentAction.LookMessageAction">
			<result name="success">/student/lookMessage.jsp</result>
			<result name="input">/student/index.jsp</result>
		</action>
		
		<action name="addMessageAction" class="studentAction.AddMessageAction">
			<result name="success" type="chain">lookMessageAction</result>
			<result name="input">/student/addMessage.jsp</result>
		</action>
		
		<action name="findMessageAction" class="studentAction.FindMessageAction">
			<result name="success">/student/updateMessage.jsp</result>
			<result name="input">/student/findMessage.jsp</result>
		</action>
		
		<action name="updateMessageAction" class="studentAction.UpdateMessageAction">
			<result name="success" type="chain">lookMessageAction</result>
			<result name="input">/student/updateMessage.jsp</result>
		</action>
		
		<action name="deleteMessageAction" class="studentAction.DeleteMessageAction">
			<result name="success" type="chain">lookMessageAction</result>
			<result name="input">/student/deleteMessage.jsp</result>
		</action>
	</package>
</struts>

addMessage.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<title><s:text name="学生信息管理系统-增加"></s:text></title>
	</head>
	<body bgcolor="pink">
		<div align="center">
			<hr color="red">
			<br>
			<table align="center" width="80%">
				<tr>
					<td width="25%">
						<s:a href="http://localhost:8080/ch06/student/lookMessage.jsp"> 
							查看学生信息
						</s:a>
					</td>
					<td width="25%">
						添加学生信息
					</td>
					<td width="25%">
						<s:a href="http://localhost:8080/ch06/student/findMessage.jsp">
							修改学生信息
						</s:a>
					</td> 
					<td width="25%">
						<s:a href="http://localhost:8080/ch06/student/deleteMessage.jsp"> 
						删除学生信息
						</s:a>
					</td>
				</tr>
			</table>
			<br>
			<hr color="red" />
			<center><font color="red" size="6"></font></center>
		</div>
		<s:form action="addMessageAction" method="post">
			<table align="center" width="30%" bgcolor="gray" border="5">
				<tr>
					<td>
						<s:textfield name="id" label="学号"></s:textfield>
					</td>
					<td>
						<s:textfield name="name" label="姓名"></s:textfield>
					</td>
					<td>
						<s:select name="sex" label="性别" list="{'男','女'}"></s:select>
					</td>
					<td>
						<s:textfield name="age" label="年龄"></s:textfield>
					</td>
					<td>
						<s:textfield name="weight" label="体重"></s:textfield>
					</td>
					<td colspan="2">
						<s:submit value="提交"></s:submit>
						<s:reset value="清除"></s:reset>
				</tr>
			</table>
		</s:form>
	</body>
</html>

deleteMessage.jsp

<%@page import="PO.Stuinfo" %>
<%@page import="java.util.ArrayList" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<title><s:text name="学生信息管理系统-删除"></s:text></title>
	</head>
	<body bgcolor="pink">
		<div align="center">
		<hr color="red"/>
		<br>
		<table align="center" width="80%">
			<tr>
				<td width="25%">
					<s:a href="http://localhost:8080/ch06/student/lookMessage.jsp"> 
							查看学生信息
					</s:a>
				</td>
				<td width="25%">
					<s:a href="http://localhost:8080/ch06/student/addMessage.jsp"> 
						添加学生信息
					</s:a>
				</td>
				<td width="25%">
					<s:a href="http://localhost:8080/ch06/student/findMessage.jsp">
						修改学生信息
					</s:a>
				</td> 
				<td width="25%">
						删除学生信息
				</td>
			</tr>
		</table>
		<br/>
		<hr color="red"/>	
		<br/><br/><br/>
		<font size="5">删除学生信息</font>
		</div>
		<s:form action="deleteMessageAction" method="post">
			<table align=" center" width="40%" border ="5">
				<tr>
					<td>
						请选择要删除学生的学号:
					</td>
					<td>
						<select name="id">
							<%
								ArrayList list=(ArrayList)session.getAttribute("allInfo");
								if(list.isEmpty()){
							%>
								<option value="null">null</option>
							<%
								}
								else{
									for(int i=0;i<list.size();i++){
										Stuinfo info=(Stuinfo)list.get(i);
							%>
								<option value="<%=info.getId() %>"> <%=info.getId() %> </option>
							<%
									}
								}
							%>
						</select>
					</td>
					<td>
						<s:submit value="确定"></s:submit>
					</td>
				</tr>
			</table>
		</s:form>
	</body>
</html>

findMessage.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<%@page import="java.util.ArrayList,PO.Stuinfo" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<title><s:text name="学生信息管理系统-查找"></s:text></title>
	</head>
	<body bgcolor="pink">
		<div align="center">
			<hr color="red">
			<br>
			<table align="center" width="80%">
				<tr>
					<td width="25%">
						<s:a href="http://localhost:8080/ch06/student/lookMessage.jsp"> 
							查看学生信息
						</s:a>
					</td>
					<td width="25%">
						<s:a href="http://localhost:8080/ch06/student/addMessage.jsp"> 
						添加学生信息
						</s:a>
					</td>
					<td width="25%">					
							修改学生信息
					</td> 
					<td width="25%">
						<s:a href="http://localhost:8080/ch06/student/deleteMessage.jsp"> 
						删除学生信息
						</s:a>
					</td>
				</tr>
			</table>
			<br>
			<hr color="red" />
			<br>	<br>	<br>
			<font size="5">修改学生信息</font>
		</div>
		<s:form action="findMessageAction" method="post">
			<table align="center" width="40%" bgcolor="gray" border="5">
				<tr>
					<td>
						请选择要修改学生的学号
					</td>
					<td>
						<select name="id">
							<%
								ArrayList list=(ArrayList)session.getAttribute("allInfo");
							if(list.isEmpty()){
							%>
								<option value="null">null</option>
							<%
							}
							else{
								for(int i=0;i<list.size();i++){
									Stuinfo info=(Stuinfo)list.get(i);
							%>
								<option value="<%=info.getId() %>"> <%=info.getId() %> </option>
							<%
									}
								}
							%>
						</select>
					</td>
					<td>
						<s:submit value="确定"></s:submit>
					</td>
				</tr>
			</table>
		</s:form>
	</body>
</html>

index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<title><s:text name="基于SH的学生信息管理-起始页"></s:text></title>
	</head>
	<body bgcolor="#CCCCFF">
		<div align="center">
			<br><br><br><br><br>
			<font color="black" size="6">
				基于Struts2+Hibernate5的学生信息管理系统实例,可对学生信息进行增、删、改、查!
			</font>
			<br><br><br>
			<s:a href="lookMessageAction">
				<font color="blue" size="6">点击进入</font>
			</s:a>
		</div>
	</body>
</html>

lookMessage.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"
		 import="java.util.ArrayList,PO.Stuinfo"%> 
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<title><s:text name="学生信息管理系统-查看"></s:text></title>
	</head>
	<body bgcolor="pink">
		<div align="center">
		<hr color="red"/>
		<br>
		<table align="center" width="80%">
			<tr>
				<td width="25%">
					查看学生信息
				</td>
				<td width="25%">
					<s:a href="http://localhost:8080/ch06/student/addMessage.jsp"> 
						添加学生信息
					</s:a>
				</td>
				<td width="25%">
					<s:a href="http://localhost:8080/ch06/student/findMessage.jsp">
						修改学生信息
					</s:a>
				</td> 
				<td width="25%">
					<s:a href="http://localhost:8080/ch06/student/deleteMessage.jsp"> 
						删除学生信息
					</s:a>
				</td>
			</tr>
		</table>
		<br/>
		<hr color="red"/>	
		<br/><br/><br/>
		<span>你要查询的数据表中共有
			<%=request.getSession().getAttribute("count")%></span>
		</div>
		<table align=" center" width="80%" border ="5">
			<tr>
				<th>记录条数</th>
				<th>学号</th>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
				<th>体重</th>
			</tr>
			<%
				ArrayList list=(ArrayList)session.getAttribute("allInfo");
				if(list.isEmpty()){
			%>
				<tr>
					<td align="center">
						<span>暂无学生信息!</span>
					</td>
				</tr>
			<%
				}else{
					for(int i=0;i<list.size();i++){
						Stuinfo info=(Stuinfo)list.get(i);
			%>
				<tr>
					<td align="center"><%=i+1 %></td>
					<td><%=info.getId()%></td>
					<td><%=info.getName()%></td>
					<td><%=info.getSex()%></td>
					<td><%=info.getAge()%></td>
					<td><%=info.getWeight()%></td>
				</tr>
			<%
					}
				}
			%>
		</table>
	</body>
</html>

updateMessage.jsp

<%@page import="PO.Stuinfo" %>
<%@page import="java.util.ArrayList" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<title><s:text name="学生信息管理系统-修改"></s:text></title>
	</head>
	<body bgcolor="pink">
		<div align="center">
			<hr color="red">
			<br>
			<table align="center" width="80%">
				<tr>
					<td width="25%">
						<s:a href="http://localhost:8080/ch06/student/lookMessage.jsp"> 
							查看学生信息
						</s:a>
					</td>
					<td width="25%">
						<s:a href="http://localhost:8080/ch06/student/addMessage.jsp"> 
						添加学生信息
						</s:a>
					</td>
					<td width="25%">					
							修改学生信息
					</td> 
					<td width="25%">
						<s:a href="http://localhost:8080/ch06/student/deleteMessage.jsp"> 
						删除学生信息
						</s:a>
					</td>
				</tr>
			</table>
			<br>
			<hr color="red" />
			<br><br><br>
			<font size="5">修改学生信息</font>
		</div>
		<s:form action="updateMessageAction" method="post">
			<table align="center" width="30%" bgcolor="gray" border="5">
				<%
					ArrayList list=(ArrayList)session.getAttribute("oneInfo");
					Stuinfo info=(Stuinfo)list.get(0);
				%>
					<tr>
						<td>
							学号
						</td>
						<td>
							<input name="id" value="<%=info.getId() %>" readonly="readonly">
						</td>
					</tr>
					<tr>
						<td>
							姓名
						</td>
						<td>
							<input name="name" value="<%=info.getName() %>" >
						</td>
					</tr>
					<tr>
						<td>
							性别
						</td>
						<td>
							<input name="sex" value="<%=info.getSex() %>" >
						</td>
					</tr>
					<tr>
						<td>
							年龄
						</td>
						<td>
							<input name="age" value="<%=info.getAge() %>" >
						</td>
					</tr>
					<tr>
						<td>
							体重
						</td>
						<td>
							<input name="weight" value="<%=info.getWeight() %>" >
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<s:submit value="提交"></s:submit>
						</td>
					</tr>			
					<tr>
						<td align="center" colspan="2">
							<s:a href="http://localhost:8080/ch06/student/findMessage.jsp">返回</s:a>
						</td>
					</tr>		
			</table>
		</s:form>
	</body>
</html>

你可能感兴趣的:(mysql,hibernate,struts2)