第一种:在Action中使用ActionContext类和ServletActionContext类。
例如:在Action中的任一个方法中:
HttpServletRequest request=ActionContext.getContext().get(org.apache.struts2.StrutsStatus.HTTP_REQUEST);
第二种:让Action实现ServletRequestAware接口。
例如:import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.*;
public class Actions extends ActionSupport implements ServletRequestAware{
String str="abcdef";
public String execute() throws Exception{
request.setAttribute("strs",str);
}
}
注:之所以上面的Action继承ActionSupport类,是因为继承后,可以使用其内部的一些方法,更简易以后的开发。
以上只是一些小的总结,有待完善!