How to get a Servlet Request attribute in Struts 2.2.1?
I'm reading some tutorial where before invocati开发者_开发百科ng any action there is a filter that sets an attribute in the ServletRequest as Connection.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
Connection connection = new ConnectionFactory().getConnection();
request.setAttribute("connection", connection);
chain.doFilter(request, response);
connection.close();
}
However I still didn't find a way to get the attribute in my Action. How can I get it?
Map parameters = ActionContext.getContext().getParameters();
Another option is that your action class implements ServletRequestAware
. In the implementation of the method you simply assign the request to an instance field.
精彩评论