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创建的 ...
随机推荐
- 【USACO 3.1.6】邮票
[描述] 已知一个N枚邮票的面值集合(如,{1分,3分})和一个上限K ——表示信封上能够贴K张邮票.计算从1到M的最大连续可贴出的邮资. 例如,假设有1分和3分的邮票:你最多可以贴5张邮票.很容易贴 ...
- SecureCRT上使用公钥登陆Linux服务器
SecureCRT部分配置 1.首先生成公钥. 打开SecureCRT(我的版本为7.0,估计其他版本基本相同)程序,点击菜单栏的“工具”->“创建公钥”.按照步骤执行.其中一步比较重要就是选择 ...
- Python正则表达式+自创口诀
重新学习了Python正则表达式,看了一些很好的学习博客,向大家推荐这个. 感谢作者@AstralWind 博客地址:http://www.cnblogs.com/huxi/archive/2010/ ...
- C# Ini文件操作
在开源中国看到的操作ini文件的,写的还不看,留着以后用 using System; using System.IO; using System.Runtime.InteropServices; us ...
- scrapy1.1入门用例简介
今天将scrapy安装成功,测试了下,倒腾了好长时间,才倒腾成功,特此分享. 其实最好的老师就是scrapy的帮助文档,只要把文档看懂,照着做,也就啥都会儿了! 帮助文档下载见http://downl ...
- python:UnboundLocalError: local variable 'xxx' referenced before assignment
近来一直都在学习python语言,偶然在伯乐在线看到2017年京东C/C++的面试题.就打算用python+ST3 IDE顺便敲下面试题代码. 原题 C语言: #include <stdio.h ...
- ES聚合实例
在es中需要根据app_categor进行聚合,JSON查询语句如下: { "query": { "bool": { "must": [ { ...
- JS简易时钟
HTML <div id="clock"> <span></span>:<span></span>:<span&g ...
- JAVA基础(1)之hashCode()
JAVA基础(1)之hashCode() 看到一篇关于hashCode的文章(),写的很详细明白,瞬间有种恍然大悟的感觉,所以特地转过来.原文:http://blog.csdn.net/fenglib ...
- 转:zookeeper3.4.5安装笔记
文章来自于:http://mmicky.blog.163.com/blog/static/150290154201392893623943/ 1:解压 官网zookeeper.apache.org ...