Struts2+Ajax

1.导入jar包

struts核心包:

json需要的包:

2.Action配置

public class UserAction extends ActionSupport implements ServletRequestAware {

private String username;

private String userpwd;

private HttpServletRequest request;


public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getUserpwd() {
    return userpwd;
}

public void setUserpwd(String userpwd) {
    this.userpwd = userpwd;
}

@Override
public void setServletRequest(HttpServletRequest arg0) {

    this.request = arg0;
}

public void executeAjax() throws IOException {

    // 处理Ajax请求

    String name = request.getParameter("username");
    
    String pwd = request.getParameter("userpwd");

    HttpServletResponse response = ServletActionContext.getResponse();
    
    response.getWriter().print("hello"+username+"hello"+userpwd);
    
}

}

猜你喜欢

转载自www.cnblogs.com/jiangwenwen1/p/9458800.html