今天终于配置好了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. 【转】UITextView 修改键盘 的return按钮

    原文:http://www.apkbus.com/blog-107838-45740.html 1 #import <UIKit/UIKit.h>2 3 @interface TextVi ...

  2. iOS中的设计模式

    一. MVC MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离 ...

  3. plist解析, 简易实现.

    源码 class Xml { public: typedef std::pair<std::wstring, std::wstring> NodeT; static std::vector ...

  4. UVA 10254 - The Priest Mathematician (dp | 汉诺塔 | 找规律 | 大数)

    本文出自   http://blog.csdn.net/shuangde800 题目点击打开链接 题意: 汉诺塔游戏请看 百度百科 正常的汉诺塔游戏是只有3个柱子,并且如果有n个圆盘,至少需要2^n- ...

  5. jQuery 知识积累

    1.select下拉框设置选中项 //设置下拉框第一项为选中项$("#selectId option:first").prop("selected", 'sel ...

  6. Python学习笔记:04函数

    Python 函数 通过分而治之的方法解决问题是一种很自然的思路.函数就是将解决特定问题的方法进行抽象. def fibs(num): 'calculate the first num th fib ...

  7. UvaLive 6661 Equal Sum Sets (DFS)

    Let us consider sets of positive integers less than or equal to n. Note that all elements of a set a ...

  8. 用Javascript的for循环输出质数

    <body> <script type="text/javascript"> for(i=2;i<=300;i++){ var prime = tru ...

  9. System.Web.Http.Tracing 在webapi里面应用

    最近想写log.再接口里面 所以就想到了.net 4.0提供的这个类. 整好.配合asp.net api好使用 ,而且 本地调试会在 vs Output 里面输出. 1.开启这个Tracing con ...

  10. Asteroids

    http://poj.org/problem?id=3041 #include<cstdio> #include<cstring> #include<algorithm& ...