Sample.html
form
angularjs默认提交的方式是appliction/json,我在获取提交的参数username和pwd费了一番功夫,后台用struts2获取username和pwd的代码如下
SampleAction.java
InputStream is = arg0.getInputStream(); String headerJson = IOUtils.toString(is); String headerMap = new Gson().fromJson(headerJson, new TypeToken
我后来是在基类做了一个改造:
public class ActionSupportExtend extends ActionSupport implements ServletRequestAware { private HttpServletRequest request; private String headerJson; private MapheaderMap; public void setServletRequest(HttpServletRequest arg0) { this.request = arg0; try { InputStream is = arg0.getInputStream(); this.headerJson = IOUtils.toString(is); this.headerMap = new Gson().fromJson(headerJson, new TypeToken
那么在每次取用angularjs的ajax异步请求的参数,就可以直接这么写:
public class SampleAction extends ActionSupportExtend { @Override public String execute() throws Exception { String username = getHeaderAttribute("username"); String pwd = getHeaderAttribute("pwd"); // 业务逻辑代码省略 return SUCCESS; }}