今天终于配置好了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)的更多相关文章

  1. Struts2+Hibernate+Spring 整合示例

    转自:https://blog.csdn.net/tkd03072010/article/details/7468769 Struts2+Hibernate+Spring 整合示例 Spring整合S ...

  2. Struts2+Hibernate+Spring 整合示例[转]

    原文 http://blog.csdn.net/tkd03072010/article/details/7468769 Spring整合Struts2.Hibernate原理概述: 从用户角度来看,用 ...

  3. [置顶] struts2+hibernate+spring整合(annotation版)

    本博文使用struts2,hibernate,spring技术整合Web项目,同时分层封装代码,包含model层,DAO层,Service层,Action层. 在整合hibernate时使用annot ...

  4. struts2,hibernate,spring整合笔记(3)

    struts2,hibernate,spring整合笔记(1) struts2,hibernate,spring整合笔记(2) 配好struts和hibernate就要开始spring了 老规矩,还是 ...

  5. struts2,hibernate,spring整合笔记(2)

    上一话struts2,hibernate,spring整合笔记(1) 接下来继续 配置完struts之后就要开始hibernate的配置 hibernate的环境并不依赖web开发环境,在我第一次配置 ...

  6. 工作笔记3.手把手教你搭建SSH(struts2+hibernate+spring)环境

    上文中我们介绍<工作笔记2.软件开发经常使用工具> 从今天開始本文将教大家怎样进行开发?本文以搭建SSH(struts2+hibernate+spring)框架为例,共分为3步: 1)3个 ...

  7. Spring+Struts2+Hibernate框架整合流程

    一:基本步骤 新建Maven项目,导入相关依赖(推荐) 在WEB-INF的web.xml中进行配置 ————–Hibernate配置 —————- 创建entity包,创建数据库相关实体类 根据实体类 ...

  8. Spring+Struts2+Hibernate的整合

    这篇主要采用Maven搭建Spring+Struts2+Hibernate的整合项目,复习一下SSH框架,虽然spring提供自己的MVC框架, 但是Spring也提供和其他框架的无缝整合,采用组件形 ...

  9. struts2+hibernate+spring简单整合且java.sql.SQLException: No suitable driver 问题解决

    最近上j2ee的课,老师要求整合struts2+hibernate+spring,我自己其实早早地有准备弄的,现在都第9个项目了,无奈自己的思路和头绪把自己带坑了,当然也是经验问题,其实只是用myec ...

  10. Struts2学习笔记——Struts2与Spring整合

      Struts2与Spring整合后,可以使用Spring的配置文件applicationContext.xml来描述依赖关系,在Struts2的配置文件struts.xml来使用Spring创建的 ...

随机推荐

  1. C#(WinForm)上传图片保存到数据库和从数据库读取图片显示到窗体

    //浏览图片 private void btnUp_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialo ...

  2. (转)C#Interface简介

    接口:描述可属于任何类或结构的一组相关功能,通过interface关键字来声明:接口只包含方法.委托或事件和属性的签名(接口包含的成员).不能包含字段(因为字段是包含数据的).方法的实现是“继承”接口 ...

  3. 富文本web编辑器(UEditor)

    展示效果:

  4. 离线安装maven,重新打开eclipse报错处理方法

    报错截图如下 1.eclipse 添加 jre Window -> Preferences -> Java -> Installed JREs If you can’t find a ...

  5. Jedis 一

    //连接Jedis public Jedis getJedis(){ Jedis jedis = new Jedis("192.168.1.12",6379); //权限认证 // ...

  6. 关于.net的概念

    IIS不仅仅是asp.net还有php等 所以w3wp是基本单元. 然后Managed Code加载 AppDomain, 不管是桌面程序还是asp.net程序 System.Web(HttpRunt ...

  7. 汇编-显示我放到AL中的数值

    按书上练习,有一些我看不懂. . .model flat,stdcall option casemap:none include \masmplus\include\windows.inc inclu ...

  8. Intention Locks 意向锁

    Intention Locks 意向锁 InnoDB 支持多颗粒度锁定允许row-level locks和锁整个表共存. 为了使锁在多个颗粒级别实现, 额外类型的锁被称为意向锁是被使用. . Inte ...

  9. 最近点对问题 HDU Quoit Design 1007 分治法

    #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #i ...

  10. HBase HTablePool

    Instead of creating an HTable instance for every request from your client application, it makes much ...