eclipse搭建ssh框架(二)
来源:互联网 发布:mac没有host 编辑:程序博客网 时间:2024/06/06 02:51
这篇开始整合struts2+spring
1、加入spring的包,或者是之前你已经导入所有的包,现在只需加入那个删掉的struts+spring包即可。
2、在src下复制struts.xml然后改名为spring的配置文件applicationContext.xml,并加入对struts的管理
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="loginAction" class="com.action.LoginAction" scope="prototype"> </bean> </beans>
3、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="false" /> <package name="struts2" extends="struts-default"> <!-- 此处的class的内容要与Spring配置文件中的bean的id相同 --> <action name="login" class="loginAction"> <result name="success">/result.jsp</result> <result name="input">/index.jsp</result> </action> </package></struts>
4、在web.xml加入spring相关支持
<!-- 用来定位Spring框架配置文件 ,最好放在struts配置的前面,防止出现意外错误。--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml,classpath*:applicationContext*.xml</param-value> </context-param> <!-- 配置Spring监听 ,这也放在struts前面吧。--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
5、把index.jsp改成(其实只是添加“+spring”的字眼。。)
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Hello World</title></head><body> <h1>Hello World From Struts2 + Spring</h1> <form action="login"> <label for="name">Please enter your name</label><br/> <input type="text" name="name"/> <input type="submit" value="Say Hello"/> </form></body></html>
6、重启tomcat,打开页面
点击登录后弹出
这里便完成了struts2跟spring的整合,最后一篇整合hibernate
0 0
- eclipse搭建ssh框架(二)
- Eclipse搭建SSH框架
- eclipse搭建ssh框架
- Eclipse搭建SSH框架
- eclipse搭建SSH框架
- eclipse搭建ssh框架(一)
- eclipse搭建ssh框架(三)
- eclipse中SSH三大框架环境搭建<二>
- 搭建纯SSH框架(二)
- SSH框架的搭建(二)
- 配置eclipse开发ssh框架(二)
- eclipse搭建SSH框架详解
- eclipse搭建SSH框架详解
- eclipse搭建SSH框架详解
- eclipse搭建SSH框架详解
- eclipse搭建SSH框架详解 .
- eclipse搭建SSH框架详解
- eclipse搭建SSH框架详解
- JavaScript基础知识(10)
- Untiy之Android平台读写遇到的坑
- 简单工厂
- 偶尔放松一下~
- List<T> 高级进阶 实现查询功能FindAll()
- eclipse搭建ssh框架(二)
- 00003 不思议迷宫.0009.8:Bug之一
- centos 解压压缩包到指定目录
- 观察者模式
- 设计模式一:单例模式
- 责任链模式
- Ubuntu下在Eclipse中使用真机调试Android应用
- 游戏平台搭建的思路
- C#运算符优先级