struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yasserzamani <...@git.apache.org>
Subject [GitHub] struts issue #125: Immutable context
Date Wed, 12 Apr 2017 15:09:31 GMT
Github user yasserzamani commented on the issue:

    https://github.com/apache/struts/pull/125
  
    Below is my new design which may be helpful as an example for whom is affected. Those
are about access to `%{#context['com.opensymphony.xwork2.dispatcher.HttpServletRequest'].requestURI}`.
    
    I wrote following Filter which operates after struts-prepare but before struts-execute.
It supplies an utility into request scope:
    ```
    package utils;
    
    import java.io.IOException;
    
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    
    import org.apache.struts2.StrutsStatics;
    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.util.ValueStack;
    
    /**
     * @author zamani
     *
     */
    public class MYStrutsPrepareFilter implements Filter {
    
    	private MYUtils MYUtils;
    
    	@Override
    	public void init(FilterConfig filterConfig) throws ServletException {
    		MYUtils = new MYUtils();
    	}
    
    	@Override
    	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
    			throws IOException, ServletException {
    
    		ValueStack stack = ActionContext.getContext().getValueStack();
    		stack.setValue("#request['MYUtils']", MYUtils);
    		
    		chain.doFilter(req, res);
    	}
    
    	@Override
    	public void destroy() {
    		MYUtils = null;
    	}
    
    	
    	public class MYUtils {
    		public String getRequestURI() {
    			HttpServletRequest httpsr = ((HttpServletRequest) ActionContext.getContext()
    					.get(StrutsStatics.HTTP_REQUEST));
    			return httpsr.getRequestURI();
    		}
    	}
    }
    ```
    
    Then `"#request['MYUtils'].requestURI"` can be used in jsp, instead.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message