学习笔记3:Struts2+Spring JDBC+Spring
2015-11-22 10:04
417 查看
Spring有许多功能,这里我所使用到的只是用于管理容器和Spring监听器的作用。
Spring用于管理容器时,需要添加applicationContext.xml文档系列
applicationContext.xml
其中的beans用于类,接口名称的定义,之后struts.xml文档系列中,可直接用名称指代类
struts.xml
struts-examle.xml
struts-example2.xml
另外,Spring监听器在web.xml中进行配置
这些都是新加入的配置
其他的类都与笔记2中的一样,不需要改变
Spring用于管理容器时,需要添加applicationContext.xml文档系列
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="UserDao" class="org.kingtoon.dao.impl.UserDaoImpl" /> <bean id="LoginAction" class="org.kingtoon.action.LoginAction"/> <bean id="RegisterAction" class="org.kingtoon.action.RegisterAction"/> </beans>
其中的beans用于类,接口名称的定义,之后struts.xml文档系列中,可直接用名称指代类
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.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.multipart.maxSize" value="10000000000" /> <constant name="struts.multipart.saveDir" value="/tmp" /> <!-- 登陆 --> <include file="struts-example.xml"/> <include file="struts-example2.xml"/> </struts>
struts-examle.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> <package name="example" namespace="/example" extends="struts-default"> <action name="register" class="RegisterAction" method="Regist"> <result name="success">/Congratulation.jsp</result> <result name="findit">/Login.jsp</result> <!-- <result name="input">/Register.jsp</result> --> </action> </package> </struts>
struts-example2.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> <package name="example2" namespace="/example2" extends="struts-default"> <action name="login" class="org.kingtoon.action.LoginAction" method="Login"> <result name="success">/Welcome.jsp</result> <result name="fail">/Register.jsp</result> <result name="input">/Login.jsp</result> </action> </package> </struts>
另外,Spring监听器在web.xml中进行配置
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 配置spring的监听器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext*.xml</param-value> </context-param> <filter> <filter-name>LoginFilter</filter-name> <filter-class>org.kingtoon.filter.LoginFilter</filter-class> </filter> <filter-mapping> <filter-name>LoginFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--struts的配置 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> <init-param> <param-name>config</param-name> <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>Login.jsp</welcome-file> </welcome-file-list> </web-app>
这些都是新加入的配置
其他的类都与笔记2中的一样,不需要改变
相关文章推荐
- 【Java EE (Struts2 + Spring + Hibernate)开发】:开发环境配置(待续)
- java UDP 发送报文问题
- 编程方式实现Spring的aop
- 【Java EE (Struts2 + Spring + Hibernate)开发】: Struts2(一)基本用法(待续)
- Java 文件过滤 FileFilter
- 欢迎使用CSDN-markdown编辑器
- 我的第一个JAVA程序
- java中数据的默认属性
- Caused by: java.lang.NoClassDefFoundError: com/tansuosoft/discoverx/common/Config
- Java 调用 MySQL 存储过程并获得返回值
- socket通信实例(简单的聊天室)
- Java Swing快速构建窗体应用程序
- Java练习题---判断选择循环
- java中集合选择(精简)
- @SuppressWarings注解基本用法及取值类型
- java实现Quartz定时功能
- java实现Quartz定时功能
- 浅谈.Net和Java互相调用的三种方式
- C#调用java类、jar包方法
- java API中Util包