struts2,hibernate,spring整合笔记(1)
今天终于配置好了ssh框架的整合,记录下过程供参考
环境:window8.1,jdk1.7 ,带有javaee的eclipse,也就是说要能发布web项目,TOMCAT服务器,tomcat配置涉及到环境变量,以及在eclipse中添加tomcat不在多述,struts2.1.8,hibernate3.3.2,spring2.5.6
总体结构:

lib下的jar包有几个不是必要的,但随着项目的发展估计要用到
1.配置struts2
先导入jar包

这个推荐去apps的目录下中的WEB-INF的lib中直接复制即可,在项目lib中右键paste
然后依次配置web.xml和struts.xml,值得注意的是,我的eclipse版本,在新建项目时,要点next到最后一步,单选框为General的要打勾,不然不会出现web.xml,至于后来自己添加web.xml是否可行,我并没有试过
web.xml可以直接去struts包中的例子去找,加入filter,filterMapping即可,这里贴出代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>oa</display-name> <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.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.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>
<constant name="struts.devMode" value="true" /> <package name="id" namespace="/test" extends="struts-default">
<action name="helloworld" class="com.beans.HelloWorldAction" method="execute">
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
<action name="as">
<result type="redirect">/ex.jsp</result>
</action> </package> <!-- Add packages here --> </struts>
<constant name="struts.devMode" value="true" />为开发者模式,即修改xml配置文件无需重新部署项目即可生效
第二个action是重定向,可无视
在WEB-INF/page目录下建立一个hello.jsp,随意书写
在src中创建包com.beans,创建HelloWorldAction类
package com.beans; import java.util.Date;
public class HelloWorldAction {
private String msg;
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
} public String getMsg() {
return msg;
} public void setMsg(String msg) {
this.msg = msg;
} public String execute()
{
return "success";
}
}
在webcontent加入index.jsp
至此,struts2配置完成,右键单击项目名,run as server,会显示index.jsp的页面
在浏览器中输入localhost:8080/项目名/test/helloworld
/test 对应的struts.xml中的包路径 helloworld
就会显示hello.jsp的页面,struts配置成功
配置struts中容易出现几个问题
1.action or result can not found
出现这一类问题大多是书写上的问题,或者直接就没写,action,result,返回字符串是否有空格..,多检查下即可
2.错误导入jar包,这是一个曾经困扰了我很长时间的问题,我看的第一本书,直接让我把lib下的全部jar包导入进去,那简直就是地狱,无穷无尽的错误
整个ssh的配置过程,一共花了6个小时,把这些记录下来估计也要这个时间,我会慢慢更新
因为struts之后还要与spring做一次整合,有些文件内容已经改了,改过的部分我已经还原了,但说不准又会衍生出新的问题,欢迎指正
struts2,hibernate,spring整合笔记(1)的更多相关文章
- Struts2+Hibernate+Spring 整合示例
转自:https://blog.csdn.net/tkd03072010/article/details/7468769 Struts2+Hibernate+Spring 整合示例 Spring整合S ...
- Struts2+Hibernate+Spring 整合示例[转]
原文 http://blog.csdn.net/tkd03072010/article/details/7468769 Spring整合Struts2.Hibernate原理概述: 从用户角度来看,用 ...
- [置顶] struts2+hibernate+spring整合(annotation版)
本博文使用struts2,hibernate,spring技术整合Web项目,同时分层封装代码,包含model层,DAO层,Service层,Action层. 在整合hibernate时使用annot ...
- struts2,hibernate,spring整合笔记(3)
struts2,hibernate,spring整合笔记(1) struts2,hibernate,spring整合笔记(2) 配好struts和hibernate就要开始spring了 老规矩,还是 ...
- struts2,hibernate,spring整合笔记(2)
上一话struts2,hibernate,spring整合笔记(1) 接下来继续 配置完struts之后就要开始hibernate的配置 hibernate的环境并不依赖web开发环境,在我第一次配置 ...
- 工作笔记3.手把手教你搭建SSH(struts2+hibernate+spring)环境
上文中我们介绍<工作笔记2.软件开发经常使用工具> 从今天開始本文将教大家怎样进行开发?本文以搭建SSH(struts2+hibernate+spring)框架为例,共分为3步: 1)3个 ...
- Spring+Struts2+Hibernate框架整合流程
一:基本步骤 新建Maven项目,导入相关依赖(推荐) 在WEB-INF的web.xml中进行配置 ————–Hibernate配置 —————- 创建entity包,创建数据库相关实体类 根据实体类 ...
- Spring+Struts2+Hibernate的整合
这篇主要采用Maven搭建Spring+Struts2+Hibernate的整合项目,复习一下SSH框架,虽然spring提供自己的MVC框架, 但是Spring也提供和其他框架的无缝整合,采用组件形 ...
- struts2+hibernate+spring简单整合且java.sql.SQLException: No suitable driver 问题解决
最近上j2ee的课,老师要求整合struts2+hibernate+spring,我自己其实早早地有准备弄的,现在都第9个项目了,无奈自己的思路和头绪把自己带坑了,当然也是经验问题,其实只是用myec ...
- Struts2学习笔记——Struts2与Spring整合
Struts2与Spring整合后,可以使用Spring的配置文件applicationContext.xml来描述依赖关系,在Struts2的配置文件struts.xml来使用Spring创建的 ...
随机推荐
- OC - 19.pthread和NSThread
简介 恰当的使用多线程编程可以提供任务的执行效率和系统资源的利用率 多线程是为了提高资源利用率,和应用程序的响应速度,多个线程共享应用资源 每个应用程序都有一个主线程,通常用来做UI界面刷新等 比较耗 ...
- 下拉列表框 select 动态赋值
<tr> <td class="label">所属群组:</td> <td> <select name="group ...
- Flask学习记录之使用Werkzeug散列密码
数据库中直接存放明文密码是很危险的,Werkzeug库中的security能够方便的实现散列密码的计算 security库中 generate_password_hash(password,metho ...
- 微信小程序开发之大坑记之post请求
原文:http://blog.csdn.net/walkingmanc/article/details/54237961 在微信小程序开发过程中,如果你完全按照官方文档来,那么恭喜你,90%的可能性你 ...
- TIOBE.2017.01最新编程语言排行榜
Jan 2017 Jan 2016 Change Programming Language Ratings Change1 1 Java ...
- 001Spark文件分析测试
使用spark-1.4.1-bin-hadoop2.6进行处理,测试文件大小为3G, 测试结果: 1:统计一个文件中某个字符的个数 scala> sc.textFile("/home/ ...
- mysql 主从 配置和同步管理
首先呢,需要有两个mysql服务器.如果做测试的话可以在同一台机器上装两个mysql服务程序,注意要两个运行程序的端口不能一样.我用的是一个是默认的3306,从服务器用的是3307端口. 在主服务创建 ...
- 【HDOJ】1561 The more, The Better
树状DP. /* 1561 */ #include <iostream> #include <cstdio> #include <cstring> #include ...
- POJSorting It All Out (拓扑)
题目链接. 题目大意: 给定一定的数量的小于关系: 1.如果发现环,输出从前几次就可以确定出现环 2.如果能够确定唯一序列,输出. 3.如果通过全部关系,还不能确定序列,则输出不能确定. 分析: 个人 ...
- 怎样在WIN7系统下安装IIS
http://jingyan.baidu.com/article/19192ad853224ce53f570748.html