我现在的程序是使用struct和spring实现的,我现在想在已有程序的基础上使用tiles程序的部分代码如下:
appcontext.xml部分代码<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="byName">
<!--通过JNDI获得数据源的引用-->
<bean id="zxdyDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/zxdy</value>
</property>
</bean>
<!-- 配置JdbcTemplate的bean -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref local="zxdyDataSource"/>
</property>
</bean>
<!-- 配置DBUtil的bean 并注入资源-->
<bean id="DBUtil" class="com.easygoing.util.DBUtil">
<property name="jt">
<ref local="jdbcTemplate"/>
</property>
<property name="ds">
<ref local="zxdyDataSource"/>
</property>
</bean>
<!-- Struts Action在Spring中对应的Bean -->
<!-- 本来有很多Action,但是为了方便只留下了一个,其余的一样 -->
<!--修改密码的Action-->
<bean id="CPWDAction" class="com.easygoing.form.action.ChangePwdAction" singleton="false">
<property name="dbu">
<ref local="DBUtil"/>
</property>
</bean>
</beans>
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>
<package name="zxdyQT" extends="struts-default">
<!--配置拦截器-->
<interceptors>
<interceptor name="mi" class="com.easygoing.util.MyInterceptor"/>
<interceptor-stack name="zxdydefault">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="mi"/>
</interceptor-stack>
</interceptors>
<!--配置默认拦截器-->
<default-interceptor-ref name="zxdydefault"/>
<global-results>
<result name="LOGIN">/login.jsp</result>
</global-results>
<action name="CPWDAction" class="CPWDAction">
<result name="success">
/tiles-components/changePwd.jsp
</result>
<result name="login">/login.jsp</result>
</action>
</package></struts>web.xml代码如下<?xml version="1.0" encoding="gbk"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/zxdy</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appcontext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>forward.jsp</welcome-file>
</welcome-file-list>
</web-app>
appcontext.xml部分代码<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="byName">
<!--通过JNDI获得数据源的引用-->
<bean id="zxdyDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/zxdy</value>
</property>
</bean>
<!-- 配置JdbcTemplate的bean -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref local="zxdyDataSource"/>
</property>
</bean>
<!-- 配置DBUtil的bean 并注入资源-->
<bean id="DBUtil" class="com.easygoing.util.DBUtil">
<property name="jt">
<ref local="jdbcTemplate"/>
</property>
<property name="ds">
<ref local="zxdyDataSource"/>
</property>
</bean>
<!-- Struts Action在Spring中对应的Bean -->
<!-- 本来有很多Action,但是为了方便只留下了一个,其余的一样 -->
<!--修改密码的Action-->
<bean id="CPWDAction" class="com.easygoing.form.action.ChangePwdAction" singleton="false">
<property name="dbu">
<ref local="DBUtil"/>
</property>
</bean>
</beans>
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>
<package name="zxdyQT" extends="struts-default">
<!--配置拦截器-->
<interceptors>
<interceptor name="mi" class="com.easygoing.util.MyInterceptor"/>
<interceptor-stack name="zxdydefault">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="mi"/>
</interceptor-stack>
</interceptors>
<!--配置默认拦截器-->
<default-interceptor-ref name="zxdydefault"/>
<global-results>
<result name="LOGIN">/login.jsp</result>
</global-results>
<action name="CPWDAction" class="CPWDAction">
<result name="success">
/tiles-components/changePwd.jsp
</result>
<result name="login">/login.jsp</result>
</action>
</package></struts>web.xml代码如下<?xml version="1.0" encoding="gbk"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/zxdy</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appcontext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>forward.jsp</welcome-file>
</welcome-file-list>
</web-app>
解决方案 »
- spring security 标签问题
- 关于DES加解密算法中密钥保存的问题
- 如何让A0001到A0099这样的增长
- weblogic 403错误
- 出现 java.lang.NoClassDefFoundError?
- 一个初学者
- 100分提问Eclipse+Tomcat启动问题!
- java里批量插入数据,不经过实体类
- The server encountered an internal error that prevented it from fulfilling this
- springMVC流程
- 急!高分请教!spring security的url匹配的相关问题!
- 各位大虾,请教一个css和浏览器方面的问题
LZ看看这个 不知道能不能帮到你!
看了 照着做了几遍 不对 不知道为什么郁闷ing