Marcos Roriz Junior
Marcos Roriz Junior

Reputation: 4106

How to get a Servlet Request attribute in Struts 2.2.1?

I'm reading some tutorial where before invocating 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?

Upvotes: 0

Views: 1556

Answers (1)

Bozho
Bozho

Reputation: 597422

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.

Upvotes: 1

Related Questions