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 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法