Results 1 to 2 of 2

Thread: Struts2 and session scope bean

  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Default Struts2 and session scope bean

    Hi

    I integrated spring3 with struts2. Almost everything works great but i can't access to session bean.

    Code:
     
    <bean id="account" class="account.AccountFactory" scope="session">
            <aop:scoped-proxy />
    </bean>
    In EL Expressions from JSP ${sessionScope} return J2EE class javax.servlet.jsp.el.ImplicitObjectELResolver

    so i tried everythink:
    (test is a method in account bean getTest())

    ${sessionScope.account.test} return null
    ${sessionScope['scopedTarget.account'].test} return null
    ${sessionScope.account} return null
    ${pageContext.session['account']} or ${pageContext.session['scopedTarget. account']} return "The class 'org.apache.catalina.session.StandardSessionFacade ' does not have the property 'account'."

    How to access to scope session bean when spring was integrate with strut2?

    web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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">
        
        <display-name>test</display-name>
        <context-param>
            <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
            <param-value>/WEB-INF/tiles.xml,/WEB-INF/employee-tiles.xml,/WEB-INF/teacher-tiles.xml,/WEB-INF/student-tiles.xml</param-value>
        </context-param>
        <session-config>
            <session-timeout>4</session-timeout>
        </session-config>
    
        <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>
    
        <filter>
            <filter-name>requestContextFilter</filter-name>
            <filter-class>org.springframework.web.filter.RequestContextFilte r</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>requestContextFilter</filter-name>
            <servlet-name>/*</servlet-name> <!-- Dispatcher Servlet name -->
        </filter-mapping>
    
        <listener>
            <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
        </listener>
        <listener>
            <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
        </listener>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>
    struts.xml
    Code:
    <?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="default" extends="tiles-default" namespace="/">
            <action name="news" class="newsAction">
                <result name="SUCCESS" type="tiles">module.news</result>
            </action>
        </package>
    </struts>
    Please help ...

    PS. Sorry for my english...

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    A session scoped bean is something else as a bean which is available in the http session! Next to that imho it is very bad design if you need access to your services etc. in your jsp pages. Your jsp pages should be dumb, the only thing they should do is render the model, which is prepared by the controller (Action in this case).

    If you still want to do it, use the WebApplicationContextUtils to get the bean from the applicationcontext.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •