日期:2014-05-17  浏览次数:20674 次

SSH中使用Spring的代理如何获得Servlet的相关信息
SSH中使用Spring(DelegatingActionProxy)的代理如何获得Servlet的相关信息:
本人在整个Struts1.2+Spring2.0+Hibernate3.2时,采用将所有的配置信息写到Web.xml中,以便减少框架间的耦合.
即Struts的配置采用Spring(DelegatingActionProxy)来获得,但是如果想在Action中获得Servlet的相关信息就无法获得了
以下是Spring中的Bean的配置相关信息
Java code
<!-- 配置User的Action -->
<bean name="/upload" 
    class="com.jdim.user.struts.action.PhotoAction">
    <property name="servlet">
        <bean class="org.apache.struts.action.ActionServlet"/>
    </property>
    <property name="photoService" ref="photoService" />
</bean>


如果我不配Servlet的话就获得不到ActionServlet.
但是配上后Servlet的相关信息就获得不到了.
请哪位大侠帮小弟看看,提点高见吧!!

------解决方案--------------------
代理方式没用过,也可以这样配置,参考:
楼主用的myeclipse吧,把
spring,struts,hibernate的包都扔进lib里,
web.xml配置
XML code

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

------解决方案--------------------
action中这样:记得把spring web 的包也要选进来
Java code

        WebApplicationContext wac = WebApplicationContextUtils
                .getRequiredWebApplicationContext(this.getServlet()
                        .getServletContext());
        LoginService ls = (LoginService) wac.getBean("loginService");

------解决方案--------------------
如果不会,看我发布的资源:
http://download.csdn.net/source/1147273