iteye_991 2008-11-19 16:58
浏览 250
已采纳

spring与struts整合问题

[code="java"]
value="classpath:applicationContext.xml"/>

[/code]
以上代码没有配置在struts-config.xml中,我看书上说,如果使用DelegatingActionProxy整合的话,必须把上面的代码写到配置文件里,
我的配置文件中没有,为什么程序可以执行起来,在IE上输入URL可以访问,在页面上提交数据也不会出错,知道的请告诉一下,谢谢了!
applicationContext.xml配置
[code="java"]<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd ">

<bean name="/login" class="com.maesinfo.action.UserLevelAction">
    <property name="userservice">
        <ref bean="userservice" />
    </property>
</bean>

<bean id="userservice"
    class="com.maesinfo.service.UserServiceImpl">
    <property name="userleveldao">
        <ref bean="userleveldao" />
    </property>
    <property name="userdao">
        <ref bean="userdao" />
    </property>
</bean>

<bean id="userleveldao" class="com.maesinfo.dao.UserlevelDAO" />
<bean id="userdao" class="com.maesinfo.dao.UserDAO" />

<bean id="checkUser" class="com.maesinfo.util.CheckUserLevel" />

<aop:config>
    <aop:pointcut id="allcheckmothod" expression="execution(* com.maesinfo.service.UserService.check*(..))"/>
    <aop:aspect id="checkuser" ref="checkUser">
        <aop:before method="checkLevel" pointcut-ref="allcheckmothod"/>
    </aop:aspect>
</aop:config>

[/code]

struts-config.xml配置

[code="java"]<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">



parameter="login"
type="org.springframework.web.struts.DelegatingActionProxy"
scope="request">



parameter="com.yourcompany.struts.ApplicationResources" />
<!--
spring与struts整合:把struts的Action托管给spring

value="classpath:applicationContext.xml"/>

-->

[/code]
[b]问题补充:[/b]

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
        <set-property property="contextConfigLocation" 
        value="classpath:applicationContext.xml"/>
        </plug-in>

以上代码没有配置在struts-config.xml中,我看书上说,如果使用DelegatingActionProxy整合的话,必须把上面的代码写到配置文件里,
我的配置文件中没有,为什么程序可以执行起来,在IE上输入URL可以访问,在页面上提交数据也不会出错,知道的请告诉一下,谢谢了!
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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-2.0.xsd ">

    <bean name="/login" class="com.maesinfo.action.UserLevelAction">
        <property name="userservice">
            <ref bean="userservice" />
        </property>
    </bean>
    
    <bean id="userservice"
        class="com.maesinfo.service.UserServiceImpl">
        <property name="userleveldao">
            <ref bean="userleveldao" />
        </property>
        <property name="userdao">
            <ref bean="userdao" />
        </property>
    </bean>
    
    <bean id="userleveldao" class="com.maesinfo.dao.UserlevelDAO" />
    <bean id="userdao" class="com.maesinfo.dao.UserDAO" />

    <bean id="checkUser" class="com.maesinfo.util.CheckUserLevel" />
    
    <aop:config>
        <aop:pointcut id="allcheckmothod" expression="execution(* com.maesinfo.service.UserService.check*(..))"/>
        <aop:aspect id="checkuser" ref="checkUser">
            <aop:before method="checkLevel" pointcut-ref="allcheckmothod"/>
        </aop:aspect>
    </aop:config>
</beans>
struts-config.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
    <action-mappings>
        <action path="/login" 
                parameter="login"
                type="org.springframework.web.struts.DelegatingActionProxy"
                scope="request">
            <forward name="success" path="/index.jsp"/>
        </action>
    </action-mappings>
    <message-resources
        parameter="com.yourcompany.struts.ApplicationResources" />
    <!-- 
        spring与struts整合:把struts的Action托管给spring
        <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
        <set-property property="contextConfigLocation" 
        value="classpath:applicationContext.xml"/>
        </plug-in>
    -->
</struts-config>

页面只是一个登陆页面,点击确定之后,调用login.do,然后判断一下,用户名和密码!

[b]问题补充:[/b]

页面只是一个登陆页面,点击确定之后,调用login.do,然后判断一下,用户名和密码!

[b]问题补充:[/b]
配置都在上面了!

我把下面这段配置拿掉了,程序也可以运行,但是不报错
有些书上介绍说,用DelegatingActionProxy整合,下面的配置必须加上!
我想知道为什么我的程序还可以运行?而且不报错误。
[code="java"]

value="classpath:applicationContext.xml"/>

[/code]
[b]问题补充:[/b]
[code="java"]
contextConfigLocation
classpath:applicationContext.xml

<servlet>
    <servlet-name>SpringContextServlet</servlet-name>
    <servlet-class>
        org.springframework.web.context.ContextLoaderServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

[/code]
我在web.xml加了上面的代码,是不是struts-config.xml中就不用加的代码了?
在web.xml加了这段代码之后,可以访问!

这两段代码有什么区别?

谢谢!

  • 写回答

3条回答 默认 最新

  • bohemia 2008-11-19 19:45
    关注

    [code="java"]

    value="classpath:applicationContext.xml"/>

    [/code]

    这段是需要的. 你直接访问 /login.do 可以访问么?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案