struts2+hibernate整合开发步骤
百度的各种代码,步骤,自己整合了一下
1,创建数据库
常用mysql creat table.....
2,在WebContent下的bin中添加相应的包
http://pan.baidu.com/s/1c2DR2co
本人的百度云盘分享
3,创建实体类以及相应的映射文件、
例如stuinfo.java和stuinfo.hbm.xml
stuinfo.java中包含,私有成员对象和getter,setter方法
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"?>
<!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="test">
<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>
4,配置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/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<mapping resource="PO/Stuinfo.hbm.xml"/>
</session-factory>
</hibernate-configuration>
5,创建相应的action
即各种Java动作类以及配置方法
配置文件: <result>中,当调用方法成功后,如果返回值与name中的字符串相同,就会跳转相应的页面
<!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>
相应的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;
}
}
6,在web.xml中配置启动Struts2框架的过滤器
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <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>
7,编写显示界面jsp文件
struts2+hibernate整合开发步骤的更多相关文章
- Struts2与Hibernate联合开发步骤
hibernate与struts2的联合开发步骤: 1. 建立web工程 2. 加入jar包,struts2.hibernate.数据库连接的包 3. 数据表和bean之间的映射,以及相应的映射文件* ...
- Struts2+Spring+Hibernate整合开发(Maven多模块搭建)
Struts2+Spring+Hibernate整合开发(Maven多模块搭建) 0.项目结构 Struts2:web层 Spring:对象的容器 Hibernate:数据库持久化操作 1.父模块导入 ...
- Hibernate+Spring整合开发步骤
Hibernate是一款ORM关系映射框架+Spring是结合第三方插件的大杂烩,Hibernate+Spring整合开发效率大大提升. 整合开发步骤如下: 第一步:导入架包: 1.Hibernate ...
- 轻量级Java EE企业应用实战(第4版):Struts 2+Spring 4+Hibernate整合开发(含CD光盘1张)
轻量级Java EE企业应用实战(第4版):Struts 2+Spring 4+Hibernate整合开发(含CD光盘1张)(国家级奖项获奖作品升级版,四版累计印刷27次发行量超10万册的轻量级Jav ...
- spring4+hibernate4+struts2项目整合的步骤及注意事项
首先,在整合框架之前,我们需要知道Spring框架在普通Java project和Web project中是略有不同的. 这个不同地方就在于创建IOC容器实例的方式不同,在普通java工程中,可以在m ...
- struts2+hibernate整合-实现登录功能
最近一直学习struts2+hibernate框架,于是想把两个框架整合到一起,做一个小的登录项目.其他不多说,直接看例子. 1).Struts2 和hibernate的环境配置 包括jar包.web ...
- [Java web]Spring+Struts2+Hibernate整合过程
摘要 最近一直在折腾java web相关内容,这里就把最近学习的spring+struts2+hibernate进行一个整合,也就是大家经常说的ssh. 环境 工具IDE :Idea 2018 数据库 ...
- 框架篇:Spring+SpringMVC+hibernate整合开发
前言: 最近闲的蛋疼,搭个框架写成博客记录下来,拉通一下之前所学知识,顺带装一下逼. 话不多说,我们直接步入正题. 准备工作: 1/ IntelliJIDEA的安装配置:jdk/tomcat等..(本 ...
- 开发步骤Dubbo、spring mvc、springboot、SSM整合开发步骤
一.Dubbo开发步骤: 链接:https://pan.baidu.com/s/1pMPO1kf 密码:9zaa 第一: 1.创建consumer工程2.在pom.xml文件下添加配置3.添加appl ...
随机推荐
- java 多线程2
class MyThread extends Thread { @Override public void run() { super.run(); for (int i = 0; i < 50 ...
- 【转】 C++中delete和delete[]的区别
一直对C++中的delete和delete[]的区别不甚了解,今天遇到了,上网查了一下,得出了结论.做个备份,以免丢失. C++告诉我们在回收用 new 分配的单个对象的内存空间的时候用 delete ...
- Linq分页查询
//Linq分页查询 int pageIndex = Convert.ToInt32(HttpContext.Current.Request["PageIndex"]); int ...
- Disney English
项目大体流程是做几个页面的模板,然后后台用html改成phtml 但是后期连模板都要改掉,很多都无法考虑到复用 css很混乱,js已经忘记了
- NCrawler 学习
NCrawler是一款国外的开源网络爬虫软件,遵循LGPL许可协议.其HTML处理使用的是htmlagilitypack开源库,采用xpath的方式处理定位网页元素,十分方便.同时其采用HttpWeb ...
- Unique Paths II [LeetCode]
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 452. Minimum Number of Arrows to Burst Balloons——排序+贪心算法
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- 工程技巧Linux上建立工程项目
程序中用到的核心代码用库的形式进行封装,并且给出示例程序,下面给出一个程序文件夹的建立脚本. 如运行sh MakeProject.sh PersonNameIdentification PNILib ...
- JDicom使用指南
适用条件本指南用于使用JDicom进行环境模拟.产品调试. 一.安装JDicom运行JDicom安装程序之前,需安装JRE 1.3及以上版本.否则,弹出如下图所示报错 安装JRE 1.4:双击运行可执 ...
- Window["aaa"]这个在JS里是什么意思?
答案:定义一个全局的变量 aaa,这个的方式是数组,实际上是等于 window.aaa