Spring3.0+Struts2.2+Hibernate3.6+ExtJS3.2.0+DWR框架 整合四
一、实现WEB层
package com.hanz.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.hanz.domain.Department;
import com.hanz.domain.Popedom;
import com.hanz.domain.User;
import com.hanz.service.DepartmentService;
import com.hanz.service.PopedomService;
import com.hanz.service.UserService;
import com.hanz.util.UserGridPrint;
import com.opensymphony.xwork2.ActionContext;
@Component("user")
public class UserAction extends BaseAction {
private UserService userService;
@Resource(name = "userService")
public void setUserService(UserService userService) {
this.userService = userService;
}
private DepartmentService departmentService;
@Resource(name = "departmentService")
public void setDepartmentService(DepartmentService departmentService) {
this.departmentService = departmentService;
}
private PopedomService popedomService;
@Resource(name = "popedomService")
public void setPopedomService(PopedomService popedomService) {
this.popedomService = popedomService;
}
private PageBean pageBean;// 包含分布信息的bean
private int start;
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
private int limit;
public PageBean getPageBean() {
return pageBean;
}
public void setPageBean(PageBean pageBean) {
this.pageBean = pageBean;
}
public String login() throws Exception {
String status = request.getParameter("status");
String username = request.getParameter("username");
String pwd = request.getParameter("pwd");
PrintWriter out = response.getWriter();
try {// 非法身份导致异常
Integer.valueOf(status);
} catch (Exception e) {
out.write("{'success':false}");
out.flush();
out.close();
e.printStackTrace();
return null;
}
System.out.println("status:" + status + ";username:" + username
+ ";pwd:" + pwd);
// 组装用户对象并验证
User user = new User();
user.setPopedom((Popedom) popedomService.get(Popedom.class, Integer.valueOf(status)));
user.setUser_code(username);
user.setPwd(pwd);
User u = userService.login(user);
if (u != null) {
Map session = ActionContext.getContext().getSession();
session.put(WebConstant.USER,u);
out.write("{'success':true}");
} else {
out.write("{'success':false}");
}
out.flush();
out.close();
return null;
}
public String alter() throws Exception {
String userid = request.getParameter("userid");
Integer userid_id = Integer.parseInt(userid);
String status_m = request.getParameter("status_m");
Integer status_Id = Integer.parseInt(status_m);
String department_m = request.getParameter("department_m");
Integer department_Id = Integer.parseInt(department_m);
String user_code_ = request.getParameter("user_code_");
String pwd_ = request.getParameter("pwd_");
String name_ = request.getParameter("name_");
String sex_ = request.getParameter("sex_");
String email_ = request.getParameter("email_");
System.out.println("新建部门信息页面-->接收到参数:");
System.out.println("status_m:" + status_m + "|department_m:"
+ department_m + "|user_code_:" + user_code_);
User user = new U