基于struts2,hibernate的小javaweb项目

19:47:49

这是截图

闲话不说 就开始了

web-xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" 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_2_5.xsd">

    <!-- structs2的配置 -->

    <filter>

        <filter-name>struts2</filter-name>

        <filter-class>

            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

        </filter-class>

    </filter>

 

    <filter-mapping>

        <filter-name>struts2</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

 

    <welcome-file-list>

        <welcome-file>index.jsp</welcome-file>

    </welcome-file-list>

</web-app>

 struts-xml:

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

 "http://struts.apache.org/dtds/struts-2.0.dtd">

 

<struts>

 

    <package name="default" extends="struts-default">

        <!-- 用于页面重转 -->

        <action name="turnaddMessage" class="sedion.xq.action.turnAction">

            <result name="success">

                /WEB-INF/student/addMessage.jsp

            </result>

        </action>

 

        <action name="turndeleteMessage" class="sedion.xq.action.turnAction"

            method="getid">

            <result name="success">

                /WEB-INF/student/deleteMessage.jsp

            </result>

        </action>

        <action name="turnfindMessage" class="sedion.xq.action.turnAction"

            method="getid">

            <result name="success">

                /WEB-INF/student/findMessage.jsp

            </result>

 

        </action>

        <!-- look stu message -->

        <action name="lookMessageAction" class="sedion.xq.action.lookMessageAction">

            <result name="success">

                /WEB-INF/student/lookMessage.jsp

            </result>

            <result name="input">/index.jsp</result>

        </action>

 

        <!-- delet stu message -->

        <action name="deleteMessageAction" class="sedion.xq.action.deleteMessageAction">

            <result name="success" type="chain">

                lookMessageAction

            </result>

            <result name="input">/student/deleteMessage.jsp</result>

        </action>

        <!-- add stu message -->

        <action name="addMessageActon" class="sedion.xq.action.addMessageAction">

            <result name="success" type="chain">

                lookMessageAction

            </result>

            <result name="input">/student/deleteMessage.jsp</result>

        </action>

 

        <!-- find stu message -->

 

        <action name="findMessageAction" class="sedion.xq.action.findMessageAction">

            <result name="success">

                /WEB-INF/student/updateMessage.jsp

            </result>

            <result name="input">/student/findMessage.jsp</result>

        </action>

        <!-- update stu message -->

 

        <action name="updateMessageActon" class="sedion.xq.action.updateMessageAction">

            <result name="success" type="chain">

                lookMessageAction

            </result>

            <result name="input">/WEB-INF/student/updateMessage.jsp</result>

        </action>

    </package>

 

</struts>

 hibernate.cfg.xml:(申明 这里用的是SQL service 2005   若修改 这里修改 链接数据库    该数据库  名字LQQ  里面一张表格   在最后会发布)

<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE hibernate-configuration PUBLIC

 "-//Hibernate/Hibernate Configuration DTD3.0//EN"

 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

 

<!-- Generated by MyEclipse Hibernate Tools.  -->

<hibernate-configuration>

    <session-factory>

        <property name="connection.username">sa</property>

        <property name="connection.url">

            jdbc:jtds:sqlserver://localhost:1433;DatabaseName=LQQ

        </property>

        <property name="dialect">

            org.hibernate.dialect.SQLServerDialect

        </property>

        <!--<property name="myeclipse.connection.profile">

            LoginSystem

            </property>  -->

        <property name="connection.password">sa</property>

        <property name="connection.driver_class">

            net.sourceforge.jtds.jdbc.Driver

        </property>

        <property name="show_sql">true</property>

        <!-- POJO 类映射配置-->

        <mapping resource="sedion/xq/ORM/Stuinfo.hbm.xml" />

    </session-factory>

</hibernate-configuration>

 然后 贴出  HibernateSessionFactory.java:

package sedion.xq.hibernate;

 

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

            System.out.println(configure);

            sessionFactory = configure.buildSessionFactory();

        } catch (Exception e) {

            // TODO: handle exception

            System.out.println("HibernateSessionFactory  wrong!!");

            message("生成SessionFactory失败"+e);

        }

    }

 

    public static Session getSession() {

        System.out.println(sessionFactory.openSession());

        return sessionFactory.openSession();

    }

    public static void message(String mess){

        int type=JOptionPane.YES_NO_CANCEL_OPTION;

        String title="提示消息";

        JOptionPane.showMessageDialog(null,mess,title, type);

    }

}

 

然后 再贴出  ORM:

Stuinfo.java:

package sedion.xq.ORM;

 

public class Stuinfo {

    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(自然可以根据这个表格  还原数据库的表格  表名:stuinfo):

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0

//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

    <class name="sedion.xq.ORM.Stuinfo" table="stuinfo">

        <id name="id" type="string">

            <column name="id" length="20" />

            <generator class="assigned" />

        </id>

        <property name="name" type="string" length="20" />

        <property name="sex" type="string" length="5" />

        <property name="age" type="integer" />

        <property name="weight" type="float" />

    </class>

</hibernate-mapping>

 

然后 再贴出  DAO层:

StudentDao.java:

package sedion.xq.DAO;

 

import java.util.List;

 

import javax.swing.JOptionPane;

 

import org.hibernate.Query;

import org.hibernate.Session;

import org.hibernate.Transaction;

 

import sedion.xq.ORM.Stuinfo;

import sedion.xq.hibernate.HibernateSessionFactory;

import sun.swing.UIAction;

 

public class StudentDao {

    private Transaction transaction;

    private Session session;

    private Query query;

 

    public StudentDao() {

 

    }

 

    // 显示

    public List findAllInfo() {

        session = HibernateSessionFactory.getSession();

        try {

            transaction = session.beginTransaction();

            String querysString = "from Stuinfo";

            query = session.createQuery(querysString);

            List<Stuinfo> list = query.list();

            System.out.println(list);

            transaction.commit();

            session.close();

            return list;

        } catch (Exception e) {

 

            message("findInfo.error" + e);

            e.printStackTrace();

            return null;

        }

    }

 

    // save message

 

    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 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 List<Stuinfo> findInfo(String id) {

        try {

            session = HibernateSessionFactory.getSession();

            transaction = session.beginTransaction();

            query = session.createQuery("from Stuinfo stu where stu.id like?");

            query.setString(0, id);

            List<Stuinfo> list = query.list();

            System.out.println(list);

            transaction.commit();

            session.close();

            return list;

        } catch (Exception e) {

            message("deleteInfo.error" + e);

            e.printStackTrace();

            return null;

        }

    }

 

    public boolean updateInfo(Stuinfo info,String id) {

        try {

            System.out.println(id+"didiididid");

            session = HibernateSessionFactory.getSession();

            transaction = session.beginTransaction();

            query = session.createQuery("delete from Stuinfo stu where stu.id like?");

            query.setString(0, id);

            query.executeUpdate();

            session.saveOrUpdate(info);

            transaction.commit();

            session.close();

            return true;

        } catch (Exception e) {

            message("updateInfo.error" + e);

            e.printStackTrace();

            return false;

        }

    }

 

    private void message(String mess) {

        int type = JOptionPane.YES_NO_CANCEL_OPTION;

        String title = "提示消息";

        JOptionPane.showMessageDialog(null, mess, title, type);

    }

 

}

 下面是6个 jsp:

index.JSP:

<%@  page language="java" pageEncoding="utf-8"%>

<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

    <head>

        <title>学生信息管理</title>

    </head>

 

    <body>

        <div align="center">

            <font size=6>学生信息管理系统Struts2+ Hibernate</font>

             

            <hr color="red"/>

            <font > ------made by sedion.xq</font>

            <br />

            <s:a href="lookMessageAction.action">点击进入</s:a>

        </div>

    </body>

</html>

 

lookMessage.jsp:

<%@  page language="java" pageEncoding="utf-8"%>

<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

    <head>

        <title>学生信息统一查询</title>

    </head>

 

    <body bgcolor="#7EC0EE">

        <s:div align="center">

            <hr color="red" />

            <br />

            <table align="center" width="80%">

                <tr>

                    <td width="25%">

                        查看学生信息

                    </td>

                    <td width="25%">

                        <s:a href="turnaddMessage.action">添加学生信息

                    </s:a>

                    </td>

                    <td width="25%">

                        <s:a href="turnfindMessage.action">修改学生信息

                    </s:a>

                    </td>

                    <td width="25%">

                        <s:a href="turndeleteMessage.action">删除学生信息

                    </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="2" bordercolor="blue">

            <tr>

                <th>

                    记录条数

                </th>

                <th>

                    学号

                </th>

                <th>

                    姓名

                </th>

                <th>

                    性别

                </th>

                <th>

                    年龄

                </th>

                <th>

                    体重

                </th>

            </tr>

            <s:iterator id="lsit" value="list" status="st">

                <tr>

                    <td align="center">

                        <s:property value="#st.count" />

                    </td>

                    <td>

                        ${id}

                    </td>

                    <td>

                        ${name}

                    </td>

                    <td>

                        ${sex}

                    </td>

                    <td>

                        ${age}

                    </td>

                    <td>

                        ${weight}

                    </td>

                </tr>

            </s:iterator>

 

        </table>

    </body>

</html>

 updateMessage.jsp:

<%@  page language="java" pageEncoding="utf-8"%>

<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

    <head>

        <title>学生信息--修改信息</title>

    </head>

 

    <body bgcolor="#7EC0EE">

        <s:div align="center">

            <hr color="red" />

            <br />

            <table align="center" width="80%">

                <tr>

                    <td width="25%">

                        <s:a href="lookMessageAction.action">查看学生信息</s:a>

                    </td>

                    <td width="25%">

                        <s:a href="turnaddMessage.action">添加学生信息</s:a>

                    </td>

                    <td width="25%">

                        <s:a>修改学生信息

                    </s:a>

                    </td>

                    <td width="25%">

                        <s:a href="turndeleteMessage.action">删除学生信息

                    </s:a>

                    </td>

                </tr>

            </table>

            <br />

            <hr color="red" />

            <br />

            <br />

            <br />

            <center>

                <font color="black" size="6">修改学生信息</font>

            </center>

        </s:div>

        <s:form action="updateMessageActon" method="post">

            <table align="center" width="30%" border="2">

                <s:iterator value="list" id="list">

                    <tr>

                        <td>

                            <s:textfield readonly="true" name="id" label="学号" maxLength="16" value="%{id}">

                            </s:textfield>

                        </td>

                        <td>

                            <s:textfield name="name" label="姓名" value="%{name}">

                            </s:textfield>

                        </td>

                        <td>

                            <s:select name="sex" label="性别" list="{'男','女'}" value="%{sex}" />

                        </td>

                        <td>

                            <s:textfield name="age" label="年龄" value="%{age}">

                            </s:textfield>

                        </td>

                        <td>

                            <s:textfield name="weight" label="体重" value="%{weight}">

                            </s:textfield>

                        </td>

 

                        <td colspan="2">

                            <s:submit value="提交" align="center"></s:submit>

                            <s:reset value="清除" align="center"></s:reset>

                        </td>

                    </tr>

                </s:iterator>

 

            </table>

        </s:form>

        <br>

    </body>

</html>

 findMessage.jsp:

<%@  page language="java" pageEncoding="utf-8"%>

<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

    <head>

        <title>学生信息管理系统-查找</title>

    </head>

 

    <body bgcolor="#7EC0EE">

        <s:div align="center">

            <hr color="red" />

            <br />

            <table align="center" width="80%">

                <tr>

                    <td width="25%">

                        <a href="lookMessageAction.action">查看学生信息</a>

                    </td>

                    <td width="25%">

                        <s:a href="turnaddMessage.action">添加学生信息

                    </s:a>

                    </td>

                    <td width="25%">

                        <s:a>修改学生信息

                    </s:a>

                    </td>

                    <td width="25%">

                        <s:a href="turndeleteMessage.action">删除学生信息

                    </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="2" bordercolor="blue">

                <tr>

                    <td width="40%">

                        <s:select name="id" label="请选择要修改的学生的学号:" list="list.{id}"></s:select>

                    </td>

                    <td>

                        <s:submit value="确定" align="center"></s:submit>

                    </td>

                </tr>

            </table>

        </s:form>

    </body>

</html>

 deleteMessage.jsp:

<%@  page language="java" pageEncoding="utf-8"%>

<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

    <head>

        <title>学生信息--删除</title>

    </head>

 

    <body>

 

        <body bgcolor="#7EC0EE">

            <s:div align="center">

                <hr color="red" />

                <br />

                <table align="center" width="80%">

                    <tr>

                        <td width="25%">

                            <s:a href="lookMessageAction.action">查看学生信息</s:a>

                        </td>

                        <td width="25%">

                            <s:a href="turnaddMessage.action">添加学生信息

                    </s:a>

                        </td>

                        <td width="25%">

                        <s:a href="turnfindMessage.action">修改学生信息

                    </s:a>

                        </td>

                        <td width="25%">

                            <s:a>删除学生信息

                    </s:a>

                        </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="2" bordercolor="blue">

                    <tr>

                        <td width="40%">

                            <s:select name="id" label="请选择要删除的学生的学号:" list="list.{id}"></s:select>

                        </td>

                        <td >

                            <s:submit value="确定" align="center"></s:submit>

                        </td>

                    </tr>

                </table>

            </s:form>

        </body>

</html>

 addMessage.jsp:

<%@  page language="java" pageEncoding="utf-8"%>

<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

    <head>

        <title>学生信息--添加信息</title>

    </head>

 

    <body bgcolor="#7EC0EE">

        <s:div cssClass="align">

            <hr color="red" />

            <br />

            <table align="center" width="80%">

                <tr>

                    <td width="25%">

                        <s:a href="lookMessageAction.action">查看学生信息</s:a>

                    </td>

                    <td width="25%">

                        添加学生信息

                    </td>

                    <td width="25%">

                        <s:a href="turnfindMessage.action">修改学生信息

                    </s:a>

                    </td>

                    <td width="25%">

                        <s:a href="turndeleteMessage.action">删除学生信息

                    </s:a>

                    </td>

                </tr>

            </table>

            <br />

            <hr color="red" />

            <br />

            <br />

            <br />

            <center>

                <font color="black" size="6">添加学生信息</font>

            </center>

        </s:div>

        <s:form action="addMessageActon" method="post">

            <table align="center" width="30%"  border="2">

                <tr>

                    <td>

                        <s:textfield name="id" label="学号" maxLength="16">

                        </s:textfield>

                    </td>

                    <td>

                        <s:textfield name="name" label="姓名" >

                        </s:textfield>

                    </td>

                    <td>

                        <s:select name="sex" label="性别" list="{'男','女'}"/>

                    </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="提交" align="center"></s:submit>

                    <s:reset value="清除" align="center"></s:reset>

                    </td>

                </tr>

 

            </table>

        </s:form>

    </body>

</html>

 下面是6个action包里面的处理:

turnAction.java:

 

package sedion.xq.action;

 

import java.util.ArrayList;

import java.util.List;

 

import org.apache.struts2.ServletActionContext;

 

import com.opensymphony.xwork2.ActionSupport;

 

import sedion.xq.DAO.StudentDao;

import sedion.xq.ORM.Stuinfo;

 

public class turnAction extends ActionSupport {

    private List<Stuinfo> list = new ArrayList<Stuinfo>();

 

    public List<Stuinfo> getList() {

        return list;

    }

 

    public void setList(List<Stuinfo> list) {

        this.list = list;

    }

 

    public String execute() throws Exception {

 

        return "success";

 

    }

 

    public String getid() throws Exception {

        StudentDao dao = new StudentDao();

        list = dao.findAllInfo();

        return "success";

 

    }

}

 lookMessageAction.java:

package sedion.xq.action;

 

import java.util.ArrayList;

import java.util.List;

 

import javax.servlet.http.HttpServletRequest;

 

import org.apache.struts2.ServletActionContext;

 

import com.opensymphony.xwork2.ActionSupport;

import com.sun.org.apache.bcel.internal.generic.NEW;

 

import sedion.xq.DAO.StudentDao;

import sedion.xq.ORM.Stuinfo;

 

public class lookMessageAction extends ActionSupport{

    private HttpServletRequest request;

    private String message = "input";

    private List<Stuinfo> list=new ArrayList<Stuinfo>();

 

    public List<Stuinfo> getList() {

        return list;

    }

 

    public void setList(List<Stuinfo> list) {

        this.list = list;

    }

 

    @SuppressWarnings("unchecked")

    public String execute() throws Exception {

        try {      

        request = ServletActionContext.getRequest();

        StudentDao dao = new StudentDao();

        list = dao.findAllInfo();

        request.getSession().setAttribute("count", list.size());

        request.getSession().setAttribute("allInfo", list);

        message = "success";

        } catch (Exception e) {

            e.printStackTrace();

        }

        return message;

 

    }

}

 updateMessageAction:

package sedion.xq.action;

 

import javax.swing.JOptionPane;

 

import sedion.xq.DAO.StudentDao;

import sedion.xq.ORM.Stuinfo;

 

import com.opensymphony.xwork2.ActionSupport;

 

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;

    }

 

    private 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 String execute() throws Exception {

        StudentDao dao = new StudentDao();

        boolean update = dao.updateInfo(Info(),this.getId());

        if (update) {

            message = "success";

        }

        return message;

    }

 

    private void message(String mess) {

        int type = JOptionPane.YES_NO_CANCEL_OPTION;

        String title = "提示消息";

        JOptionPane.showMessageDialog(null, mess, title, type);

    }

}

 findMessageAction.java:

package sedion.xq.action;

 

import java.util.ArrayList;

import java.util.List;

 

import sedion.xq.DAO.StudentDao;

import sedion.xq.ORM.Stuinfo;

 

import com.opensymphony.xwork2.ActionSupport;

 

public class findMessageAction extends ActionSupport {

    private String id;

    private String message;

    private List<Stuinfo> list = new ArrayList<Stuinfo>();

 

    public List<Stuinfo> getList() {

        return list;

    }

 

    public void setList(List<Stuinfo> list) {

        this.list = list;

    }

 

    public String getId() {

        return id;

    }

 

    public void setId(String id) {

        this.id = id;

    }

 

    public String execute() throws Exception {

        try {

            StudentDao dao = new StudentDao();

            list = dao.findInfo(this.getId());

            message = "success";

 

        } catch (Exception e) {

            e.printStackTrace();

        }

        return message;

 

    }

 

}

 deleteMessageAction.java:

package sedion.xq.action;

 

import org.apache.struts2.ServletActionContext;

 

import sedion.xq.DAO.StudentDao;

 

public class deleteMessageAction {

    private String id;

    private String message;

 

    public String getId() {

        return id;

    }

 

    public void setId(String id) {

        this.id = id;

    }

 

    public String execute() throws Exception {

        try {

            StudentDao dao = new StudentDao();

            boolean del=dao.deleteInfo(this.getId());

            if (del) {

                message = "success";

            }

        } catch (Exception e) {

            e.printStackTrace();

        }

        return message;

 

    }

}

 addMessageAction.java:

package sedion.xq.action;

 

import java.util.List;

 

import javax.swing.JOptionPane;

 

import com.opensymphony.xwork2.ActionSupport;

import com.opensymphony.xwork2.util.finder.ClassFinder.Info;

 

import sedion.xq.DAO.StudentDao;

import sedion.xq.ORM.Stuinfo;

 

public class addMessageAction extends ActionSupport{

    /**

     *

     */

    private static final long serialVersionUID = 1L;

    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 String execute() throws Exception {

        StudentDao dao = new StudentDao();

        boolean save = dao.saveInfo(Info());

        if (save) {

            message = "success";

        }

        return message;

    }

 

    private 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;

    }

 

    private void message(String mess) {

        int type = JOptionPane.YES_NO_CANCEL_OPTION;

        String title = "提示消息";

        JOptionPane.showMessageDialog(null, mess, title, type);

    }

}

 终于到最后了  , 下面发下  表格的截图

  

 

 谢谢  java大师我的偶像   一步一步接近

时间: 2024-11-08 22:26:17

基于struts2,hibernate的小javaweb项目的相关文章

有木有Struts2+hibernate+spring+mysql的项目源码?求!!!

问题描述 如题!!!要求项目能运行无误...数据库有创建数据库文件...如果谁有请联系我..QQ:506846716:先谢谢了!

求救:spring+struts2+hibernate事务

问题描述 用spring+struts2+hibernate做了一个项目,一切正常,只是睡一晚上起来再打开就出现以下异常,然后刷新一下就又没事了.什么原因?望大位大虾指点迷津.exceptionjavax.servlet.ServletException:org.springframework.transaction.CannotCreateTransactionException:CouldnotopenHibernateSessionfortransaction;nestedexceptio

急求struts2+hibernate+oracle开发项目源代码!!!

问题描述 急求struts2+hibernate+oracle开发项目源代码!!! 用struts2+hibernate+oracle开发的发布系统 解决方案 这个可不好求啊.....

Struts2+Hibernate实现数据分页的方法_java

本文实例讲述了Struts2+Hibernate实现数据分页的方法.分享给大家供大家参考,具体如下: 1.用Hibernate实现分页技术: /** * 使用hql语句进行分页查询 * @param hql 需要查询的hql语句 * @param offset 第一条记录索引 * @param pageSize 每页需要显示的记录数 * @return 当前页的所有记录 */ @SuppressWarnings("unchecked") public List findByPage(f

同一javaweb项目在同样配置的两台Linux服务器上,一台能正常访问,另一台就报错!

问题描述 同一javaweb项目在同样配置的两台Linux服务器上,一台能正常访问,另一台就报错! java.lang.reflect.InvocationTargetException sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.Delega

JQuery+Ajax+Struts2+Hibernate框架整合实现完整的登录注册_AJAX相关

最近在仿造一个书城的网站: http://www.yousuu.com ,UI直接拿来用,前端后端自己写,目前大部分功能已经实现, 就把具体的 登录注册功能 拿来分享一下.PS:又写登录注册会不会被人喷啊=.= 一.开发环境的部署 程序结构: BootStrap+Ajax+Struts2+Hibernate+MySql 仅供参考:能实现相关功能即可 操作系统:ubuntu 14.10 前端框架:BootStrap   注:此框架只是为了实现用户界面,和具体功能无关 数据库:mysql-5.5 数

JavaEE——Intellij Idea 创建JavaWeb项目

原文:JavaEE--Intellij Idea 创建JavaWeb项目 折腾Tomcat折腾了两个晚上,第一个晚上怎么都进不了Tomcat的首页,第二个晚上进去了,但是新建的Web项目,在浏览器中运行,总是 Error on Apache Tomcat: The requested resource is not available  坑爹!!!!. 首先我要说一点,在IntelliJ IDEA里面"new Project"就相当于我们eclipse的"workspace&

sweeter-导入JavaWeb项目时,MySQL数据库报错

问题描述 导入JavaWeb项目时,MySQL数据库报错 五月 23 2014 10:19:38 上午 org.apache.catalina.core.AprLifecycleListener init信息: Loaded APR based Apache Tomcat Native library 1.1.29 using APR version 1.4.8.五月 23 2014 10:19:39 上午 org.apache.catalina.core.AprLifecycleListene

DockOne微信分享( 九十):猎豹移动基于CoreOS在AWS上的项目实践

本文讲的是DockOne微信分享( 九十):猎豹移动基于CoreOS在AWS上的项目实践[编者的话]本次分享介绍基于AWS的EC2服务如何设计和搭建适合自己业务的架构方案实现全球多region部署,介绍模型案例:CoreOS的使用技巧与运维经验,把一个集群当成一台机器管理心得,包括: 为什么选择AWS和Docker 为什么选择CoreOS部署我们的应用 CoreOS在AWS平台上如何快速构建集群并且进行管理 应用过程中遇到的问题与解决方案 1.为什么选择AWS和Docker 首先我先介绍一下猎豹