Tuesday, June 12, 2012

Access Request parameters from Struts 2 Action.

So you want to access the Request object from a Struts 2 Action. Maybe you want the User's IP address or maybe you want the Hostname?

Add these two imports:

import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;





And then pull it up like so:


HttpServletRequest request = ServletActionContext.getRequest();
String ip = request.getRemoteAddr();

1 comment: