Results 1 to 1 of 1
  1. #1
    esolve is offline Member
    Join Date
    Mar 2015
    Posts
    56
    Rep Power
    0

    Default scope of HttpServletRequest and struts.xml redirect

    I'm looking into a SSH project
    there is an `acting.jsp` file with following code block

    Java Code:
            <s:if test="#request.commonList!=null">
            <s:iterator value="%{#request.commonList}" var="common">
            <tr>
            <td> <s:property value="%{#common.stationRun}"/>  </td>
            <td> <s:property value="%{#common.devRun}"/>      </td>
            <td> <s:property value="%{#common.createDate}"/>  </td>
            </tr>
            </s:iterator>

    the request object carries `commonList` attributes. Setting of `commonList` attributes is done in java source codes:
    Java Code:
            public class BaseAction extends ActionSupport implements
                ServletRequestAware,ServletResponseAware {
    
                @SuppressWarnings("unused")
                protected HttpServletRequest request = null;
    
                @SuppressWarnings("unused")
                protected HttpServletResponse response = null;
    
                public void setServletRequest(HttpServletRequest request) {
                    this.request = request;
                }
    
                public void setServletResponse(HttpServletResponse response) {
                    this.response = response;
                }
    
            }
    Java Code:
            public elecCommonMsgAction_extends BaseAction{
    
                public String home(){
                    List<ElecCommonMsgForm> list = elecCommonMsgService.findElecCommonMsgList();
                    request.setAttribute("commonList", list);
                    return "home";
                 }
            }
    acting.jsp is redirected through struts.xml configuration

    struts.xml:
    Java Code:
            <action name="elecCommonMsgAction_*" class="cn.itcast.elec.web.action.ElecCommonMsgAction" method="{1}">
        	  <result name="home">
        	    /WEB-INF/page/system/actingIndex.jsp
        	  </result>	
        	  <result name="save" type="redirectAction">
        	    <param name="actionName">elecCommonMsgAction_home</param>
        	    <param name="namespace">/system</param>
        	  </result>   
            </action>
    In one word, JAVA source codes use the `request` object to inject `commonList` into acting.jsp


    I know there are two ways for going to another page: forward and redirect.
    Java Practices -> Forward versus redirect

    if it is forward, then the requests and request scopes are the same, otherwise, if it is redirec, then the requests and request scopes are different.

    here, in struts.xml configuration, I think it is redirection, so the request scopes are diffrerent, then how can the request.commonList correspond to the equivalent in the java source codes?
    Last edited by esolve; 12-01-2015 at 06:30 PM.

Similar Threads

  1. Replies: 1
    Last Post: 11-18-2015, 12:09 PM
  2. HttpServletRequest: which the parameters?
    By Coringa in forum New To Java
    Replies: 1
    Last Post: 08-09-2014, 08:18 AM
  3. Replies: 0
    Last Post: 04-01-2012, 03:05 PM
  4. HttpServletRequest cannot be resolved-- Help me
    By hphuoc in forum Java Servlet
    Replies: 1
    Last Post: 04-26-2011, 09:23 AM
  5. HttpServletRequest request size
    By Ed in forum Java Servlet
    Replies: 2
    Last Post: 07-02-2007, 02:02 PM

Posting Permissions

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