开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜