3
回答
Action Setter注入参数
百度AI开发者大赛带你边学边开发,赢100万奖金,加群:418589053   

DemoAction.java


public class DemoAction implements Action, ServletRequestAware {

	private HttpServletRequest request;

	@Override
	public String execute() throws Exception {

		if(request.getParameterMap().size() > 0) {
			return Action.ERROR;
		}

		return Action.SUCCESS;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
}
假设Struts2中映射的地址是/demo,如果访问/demo?ServletRequest就会给request注入一个null值,这个问题怎么避免?


举报
yanchao90
发帖于5年前 3回/157阅
顶部