基于Struts2+Hibernate的学生信息管理系统实例

蜗牛—Javaweb之简易学生管理系统(一) 最近,在学校的一个实验室学习一些java方向的知识,基于Javaweb的管理系统 由于以前关注移动开发方向,所以现在才学习web方向的东西 根据自己的理解和书上的知识。写了一个基于struts2+Hibernate的简易学生管理系统 软件为:win7旗舰版+MyEclipse10.5 创建的项目目录如下图: 加入的struts2+Hibernate的包为 首先创建一个test数 阅读详情

目录结构如下:


在mysql数据库中,建立一个数据库 stu,建立一张表stuinfo,如下图所示:



1.新建一个web project,命名为ch15,然后导入struts 2核心包和hibernate核心包,导入方法是:右击ch15这个项目,选择倒数第二项:,myeclipse,选择Add Struts 2...,导入hibernate的核心包也是一样。

2.首先要导入struts 2 核心包和hibernate核心包,但是struts 2 的核心包内的 antlr-2.x.x.jar包要删掉,删除方法是:window——>preferences——>Myeclipse——>Project  Capabilitie——>Struts 2. 然后选中右边的antlr-2.x.x.jar包,选择右边的remove,就OK啦

3.在src下建立四个包,分别为addHibernateFile, Dao,  PO,  studentAction

4.addHibernateFile下的代码(HibernateSessionFactory.java):

package addHibernateFile;

import javax.swing.JOptionPane;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateSessionFactory {
    private static SessionFactory sessionFactory;
    private static Configuration configuration=new Configuration();
    public HibernateSessionFactory(){
    }
    static{
        try{
            Configuration configure = configuration.configure("hibernate.cfg.xml");
            sessionFactory=configure.buildSessionFactory();
        }catch(Exception e){
            message("生成SessionFactoyr失败:"+e);
        }
    }
    public static Session getSession(){
        return sessionFactory.openSession();
    }
    public static void message(String mess){
        int type=JOptionPane.YES_NO_OPTION;
        String title="提示信息";
        JOptionPane.showMessageDialog(null, mess, title, type);
    }
}

5.Dao包下面的代码(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;

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){
            message("saveInfo.error:"+e);
            e.printStackTrace();
            return false;
        }
    }
    public List findInfo(String type,Object value){
        session=HibernateSessionFactory.getSession();
        try{
            transaction=session.beginTransaction();
            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){
            message("findInfo.error:"+e);
            e.printStackTrace();
            return null;
        }
    }
    public List findAllInfo(){
        session=HibernateSessionFactory.getSession();
        try{
            transaction=session.beginTransaction();
            String queryString="from Stuinfo";
            query=session.createQuery(queryString);
            List list=query.list();
            transaction.commit();
            session.close();
            return list;
        }catch(Exception e){
            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();
            session.close();
            return true;
        }catch(Exception e){
            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){
            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);
    }
}

6.PO包下面的代码:

(1)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 this.id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return this.name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getSex() {
        return this.sex;
    }
    
    public void setSex(String sex) {
        this.sex = sex;
    }
    public int getAge() {
        return this.age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public float getWeight() {
        return this.weight;
    }
    
    public void setWeight(float weight) {
        this.weight = weight;
    }
}


(2)Stuinfo.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2011-12-9 12:17:31 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="PO.Stuinfo" table="stuinfo" catalog="stu">
        <id name="id" type="string">
            <column name="id" length="20" />
            <generator class="assigned" />
        </id>
        <property name="name" type="string">
            <column name="name" length="20" not-null="true" />
        </property>
        <property name="sex" type="string">
            <column name="sex" length="5" not-null="true" />
        </property>
        <property name="age" type="int">
            <column name="age" not-null="true" />
        </property>
        <property name="weight" type="float">
            <column name="weight" precision="10" scale="0" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

7.StudentAction包下的代码:

(1)AddMessageAction.java

package studentAction;

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

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);
    }
}

(2)DeleteMessageAction.java

package studentAction;

import Dao.StudentDao;
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);
    }
}

(3)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;

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);
    }
}

(4)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();
        List list=dao.findAllInfo();
        request.getSession().setAttribute("count", list.size());
        request.getSession().setAttribute("allInfo", list);
        message="success";
        return message;
    }
}

(5)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);
    }
}

8.hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/stu</property><span style="white-space:pre">	</span><span style="font-family: Arial, Helvetica, sans-serif;"><!--stu是你建的数据库名--></span><span style="white-space:pre">
</span>    <property name="hibernate.connection.username">root</property><span style="white-space:pre">	</span><!--数据库用户名-->
    <property name="hibernate.connection.password">1234</property><span style="white-space:pre">	</span><span style="font-family: Arial, Helvetica, sans-serif;"><!--数据库用户密码--></span><span style="white-space:pre">
</span>    <mapping resource="PO/Stuinfo.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

9.struts.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <!-- Configuration for the default package. -->
    <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>

10.context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/ch15"/>

11.WebRoot下的student文件夹下的jsp文件代码:

(1)addMessage.jsp

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

(2)deleteMessage.jsp

<%@page import="PO.Stuinfo"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib  prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><s:text name="学生信息管理系统-删除"/></title>
    </head>
    <body bgcolor="pink">
        <s:div align="center">
            <hr color="red"/>
        <br/>
        <table align="center" width="80%">
            <tr>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/lookMessage.jsp">查看学生信息</s:a>
                </td>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/addMessage.jsp">添加学生信息</s:a>
                </td>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/findMessage.jsp">修改学生信息</s:a>
                </td>
                <td width="25%">
                    删除学生信息
                </td>
            </tr>
        </table>
        <br/>
        <hr color="red"/>
        <br/><br/><br/>
        <font size="5">删除学生信息</font>
        </s: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>

(3)findMessage.jsp

<%@page import="java.util.ArrayList"%>
<%@page import="PO.Stuinfo"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib  prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><s:text name="学生信息管理系统-修改"/></title>
    </head>
    <body bgcolor="pink">
        <s:div align="center">
            <hr color="red"/>
        <br/>
        <table align="center" width="80%">
            <tr>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/lookMessage.jsp">查看学生信息</s:a>
                </td>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/addMessage.jsp">添加学生信息</s:a>
                </td>
                <td width="25%">
                    修改学生信息
                </td>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/deleteMessage.jsp">删除学生信息</s:a>
                </td>
            </tr>
        </table>
        <br/>
        <hr color="red"/>
        <br/><br/><br/>
        <font size="5">修改学生信息</font>
        </s:div>
        <s:form action="findMessageAction" 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>

(4)index.jsp

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

(5)lookMessage.jsp

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.util.ArrayList,PO.Stuinfo"%>
<%@taglib  prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>学生信息管理系统-查看</title>
    </head>
    <body bgcolor="pink">
        <s: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/ch15/student/addMessage.jsp">添加学生信息</s:a>
                </td>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/findMessage.jsp">修改学生信息</s:a>
                </td>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/deleteMessage.jsp">删除学生信息</s:a>
                </td>
            </tr>
        </table>
        <br/>
        <hr color="red"/>
        <br/><br/><br/>
        <span>你要查询的数据表中共有<%=request.getSession().getAttribute("count")%>人</span>
        </s: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>

(6)updateMessage.jsp

<%@page import="PO.Stuinfo"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib  prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>学生信息管理系统-修改</title>
    </head>
    <body bgcolor="pink">
        <s:div align="center">
            <hr color="red"/>
        <br/>
        <table align="center" width="80%">
            <tr>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/lookMessage.jsp">查看学生信息</s:a>
                </td>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/addMessage.jsp">添加学生信息</s:a>
                </td>
                <td width="25%">
                    修改学生信息
                </td>
                <td width="25%">
                    <s:a href="http://localhost:8080/ch15/student/deleteMessage.jsp">删除学生信息</s:a>
                </td>
            </tr>
        </table>
        <br/>
        <hr color="red"/>
        <br/><br/><br/>
        <font size="5">修改学生信息</font>
        </s: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/ch15/student/findMessage.jsp">返回</s:a>
                        </td>
                    </tr>
            </table>
        </s:form>
    </body>
</html>

12.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>


构建基于Struts2, Hibernate和MySQL的学生信息管理系统 Struts2是Apache软件基金会的一个开源项目,它基于MVC(Model-View-Controller)架构模式,用于构建Web应用程序。Struts2框架将Web层的复杂性封装起来,简化了控制器和视图组件的创建与管理。这一设计模式将应用程序分为三部分:模型(Model)处理业务逻辑,视图(View)负责用户界面展示,控制器(Controller)负责响应用户输入并调用模型执行相应的业务逻辑,最终选择视图展示给用户。 阅读详情

相关推荐

学生信息管理系统的Struts+Hibernate实现

Struts是一种基于Java EE Web应用程序框架,遵循MVC(Model-View-Controller)设计模式。它将Web层的业务逻辑与用户界面分离,提高了代码的可维护性与可重用性。Struts框架通过Action、FormBean、Forward等组件简化了Web应用程序的开发,为开发人员提供了更加清晰的开发结构。Struts与Hibernate的集成不仅提升了开发效率,还增强了系统的稳定性和可维护性。

weixin_34945060的博客 894

struts2 与spring,hibernate 整合时需要删除的jar

1.asm.2.3.2 2.xerces-2.6.2

iteye_10357的博客 113

struts2+hibernate学生综合信息管理系统

本系统为学生综合信息管理系统,里面有学生信息管理,学生成绩录入,学生密码修改等功能,非常齐全,供学生来做项目提交给老师。 struts2+hibernate这个开发的,使用的工具为myeclipse和mysql数据库。 如有任何问题请加QQ:1255148484来提问,有问必答。

hibernate+struts2整合jar包冲突

前几天,在用Hibernate+Struts2做项目的时候遇到了一个很棘手的问题,jar包冲突!!!先亮一下错误: 之前还不知道这是个啥错误,经过上网查找之后才知道这是jar包冲突的问题!!由于项目都是用hibernate和struts2反向生成的,jar包是自动导入进来的,以为都没问题,运行的时候才出错,所以这很让人难受。 项目里面的...

weixin_33915554的博客 223

SSH(struts2+spring+hibernate)教务信息管理系统

struts2+spring+hibernate三大框架,附数据库,实现教务信息管理。

用struts1+hibernate+jsp做的简单的登录系统

我自己做的简单登录系统,用的是struts1+hibernate+jsp,里面实现了增删改查,还有分页,用了点ajax,局域网之内可以访问,实现了同一用户不能同时在多台机器上同时登陆,呵呵,做的比较累,跟大伙分享分享。

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

本项目使用Struts2+Hibernate5为开发环境,通过对学生信息进行增删改查等操作。 项目使用MySQL数据库,数据库名为student,表为stuinfo,表的字段如下所示: 项目的文件结构: HibernateSessionFactory.java package addHibernateFile; import org.hibernate.Session; import org...

monkey_wei的博客 5057

基于Struts2+hibernate+spring 注解开发的学生信息管理系统

Struts2+hibernate+spring开发,使用MySQL数据,实现学生基本信息的增删改查功能,但是页面不美观

java web应用程序案例_MVC模式在Java Web应用程序中的实例分析

MVC作为软件架构中及其重要的一种架构思想,在实际的java web项目开发中被开发者们广泛的应用。遵循MVC思想的所产生的解决方法也可以因实际情况的不同来进行不同的选择。这里以一个应用struts+hibernate+jsp的实例来进一步认识MVC。学生管理系统中添加学生模块的的MVC架构:Model(系统的业务逻辑):Hibernate进行管理的数据实体+定义的业务逻辑的体现--------数...

weixin_36459547的博客 389

很好用的学生信息管理系统,Struts2+hibernate+spring

很好用的学生信息管理系统,可以用来应付老师的作业,Struts2+hibernate+spring。带mysql数据库。

ADS与Cadence中Verilog-A文件的编译与调用实战指南

本文详细介绍了在ADS与Cadence平台中Verilog-A文件的编译与调用实战指南,涵盖开发环境配置、模型创建与编译、仿真设置技巧以及跨平台协作与调试等内容。通过具体案例和优化策略,帮助工程师高效完成混合信号仿真设计,提升电路建模与验证效率。

weixin_29196315的博客 497

hibernate+struts2学生信息管理系统简单整合

一.项目结构(MVC) 直接上图 前者是整个项目结构,webcontent包含的是前端的一些jsp文件和css样式,java resourse包含后台的一些业务逻辑处理及接口; 后者是hibernate框架涉及的部分(红线)model层下的.hbm.xml是持久化层的ORM映射文件,可以通过Eclipse直接生成: 右击持久化层的包(model)--->new-->other-->hib

bo602505401的博客 7974

新手避坑指南:HT7036计量芯片SPI读取电压的完整流程(从复位到校准)

本文详细介绍了HT7036计量芯片的SPI读取电压完整流程,从硬件准备到校准设置,重点解析了复位引脚处理、SPI通信配置、芯片初始化及数据处理等关键步骤。针对常见问题如晶振焊接、SPI时序错误等提供实用解决方案,帮助开发者高效完成电压测量与校准。

weixin_30070339的博客 326

使用Struts2+Hibernate开发学生信息管理系统

写在前面:学习java已经快两年了,写个简单的学生信息管理系统,顺便回顾下java框架的知识。一、 开发背景软件名称:学生信息管理系统(Struts2+Hibernate)使用对象:小学、初中、高中二、 需求分析 系统分析 该学生信息管理系统涉及到学生、教师、系统管理员。设置一个系统管理员对系统进行管理。所有用户需输入账号、密码登录进入系统;管理员进入系统后可对学生、老师、班级、课程进行增删改查

心猿码意 1万+

SAP中错记虚拟利润中心的调整,冲销处理实例

我非CO专业顾问。工作中遇到的问题,也会找资料,分析,测试。有时这个过程会拿到结果,解决问题。遂将过程记录下来备查。读者请谨慎参考!EC-PCA: 利润中心记账流程_9ke0-优快云博客。

专注SAP应用技术文章写作,致力于拉近用户与系统间的距离; 1796

记录一次小项目中的重放攻击与解决方案

文章目录1、重放攻击简介2、重放攻击演示3、解决方案4、重放攻击验证 欢迎各位 前(提)来(出)讨(意)论(见)。 1、重放攻击简介 重放攻击(Replay Attacks)又称重播攻击、回放攻击,是指攻击者发送一个目的主机已接收过的包,来达到欺骗系统的目的,主要用于身份认证过程,破坏认证的正确性。 举个简单的小例子。 我们往系统里面插入一条数据,如果此次操作的数据包被攻击者获取,又恰巧后台没有对重复内容进行验证,那么攻击者就可以利用该数据包重复的发起请求,无限制的往数据库插入数据,即使请求包是加密的也

fiveSix 8726

慕课网 项目实战 使用struts2和hibernate开发学生信息管理系统

.war解压缩方式:将.war放到tomcat的webapps目录下,启动tomcat服务器即可完成。 第1章 Struts2与Hibernate整合 1-3 Struts2与Hibernate整合 1)添加核心类库,注意:相同的jar包存在不同版本时,删去低版本 2)struts.xml 3)hibernate.cfg.xml

yuhan_9204的专栏 4816

ArcGIS标注(二分式、三分式、条件分类标注、上下标、牵引线、文字格式化…)

ArcGIS中的各种标注方法、可能遇到的问题和细节。

m0_73306837的博客 5268

慕课网_使用Struts2+Hibernate开发学生信息管理系统

相关软件、驱动及源代码见:https://github.com/xiaozhaowhut/imooc_sh章节结构: 第1章 Struts2与Hibernate整合 1.1 课程概述 1.2 界面原型演示 1.3 Struts2与Hibernate整合 1.4 创建实体类 1.5 生成实体类的对象关系

Howard_Zhao的博客 2334

STC8H开发(十六): GPIO模拟SPI驱动Ci24R1实现低成本无线遥控

本文详细介绍了如何使用STC8H单片机通过GPIO模拟SPI驱动Ci24R1无线模块,实现低成本无线遥控方案。内容涵盖硬件设计要点、软件驱动开发技巧及实战优化经验,特别适合消费电子产品开发者参考。Ci24R1凭借其高性价比和双模协议支持,成为替代传统nRF24L01+的理想选择。

weixin_30378623的博客 349

论文阅读-Whisper语音识别(OpenAI)

Whisper 是一个自动语音识别(ASR,Automatic Speech Recognition)系统,OpenAI 通过从网络上收集了 68 万小时的多语言,其中11万小时覆盖96 种语言,12万小时的语言标号为英语,用多任务(multitask)监督数据对 Whisper 进行了训练。

一位不是很硕的鉴伪方向硕士 6366

基于Struts和hibernate框架的学生信息管理系统

准备工作: 1、新建工程StudentMessageManagerSystem:File→New→WebProject→ProjectName→Finish 2、导入数据库驱动文件WebRoot下的WEB-INF下的lib,右键Import→FileSystem,然后选择驱动文件。 3、导入MyEclipse自带的Struts:工程名右键→MyEclipse→Add Struts Capab

笨人须下死功夫的博客 5616

计算机视觉教程2-3:图解双线性插值算法&最近邻插值算法

提出此算法的背景是基于图片的缩放,在图片缩放的过程中,实质上就是将原图像像素矩阵像素值,填到目标图像像素矩阵中,目标图像像素矩阵可能比原图像像素矩阵大(图片放大),也可能小(图片缩小)。我们假设图片的宽(WidthWidthWidth)和高(HeightHeightHeight)是按同比例缩放的,那么 srcXsrcWidth=dstXdstWidth\frac{srcX}{srcWidth}= \frac{dstX}{dstWidth}srcWidthsrcX​=dstWidthdstX​ ...

FRIGIDWINTER的博客 7283

【2024计算机毕业设计】基于jsp+mysql+Spring+hibernate+Struts2的SSH学生信息管理系统

点此进入演示地址最好是java jdk 1.8,我在这个平台上运行的。其他版本理论上也可以。Eclipse,Myeclipse,IDEA或者Spring Tool Suite都可以,如果编译器的版本太低,需要升级下编译器,不要弄太低的版本Tomcat 7.x,8.x,9.x版本均可Windows XP/7/8//8.1/10/11或者Linux或者MacOS,2G内存以上,推荐4G,4G以上更好管理员角色包含以下功能:管理员登录,学院管理,专业管理,班级管理,学科管理,学生管理,教师管理等功能。

xiaomingstart的博客 839

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

学生信息管理系统(struts2+Hibernate)(1)

第一步:配置项目中要用到的jar包(struts2+Hibernate+Junit+mysql-jdbc) 1、window-preferences-java-Bulid Path-User Libraries     在这里面添加相关jar包 2、右击项目-Properties-Java Build Path-Add Library  将jar包导入到项目组中 第二步:配置web.xml、

张巍的博客 1280

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

基于jsp+mysql+Spring+hibernate+Struts2的SSH学生信息管理系统

运行环境: 最好是java jdk 1.8,我在这个平台上运行的。其他版本理论上也可以。 IDE环境:

codes_su的博客 363

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

上一篇: myeclipse报错:Building workspace' has encountered a problem. Errors occurred during the build
下一篇: Hibernate是怎么工作的——Hibernate的工作流程
冷静BB
博客等级 码龄12年 298粉丝 112原创
评论 12
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值