日期:2014-05-17 浏览次数:20634 次
<form action="${pageContext.request.contextPath}/user/userAction" method="post" id="edit_dialog"><table border="0" cellpadding="0" cellspacing="0" style="width:540px;height:320px;"><tr><th valign="top">用户名:</th><td><input type="text" name="user.username"/></td></tr><tr><th valign="top">密码:</th><td><input type="text" name="user.password"/></td></tr><tr><th valign="top">真实姓名:</th><td><input type="text" name="user.realname"/></td></tr><tr><th valign="top">电话:</th><td><input type="text" name="user.tel"/></td></tr><tr><th valign="top">证件号码:</th><td><input type="text" name="user.cardnum"/></td></tr><tr><th valign="top">地址:</th><td><textarea name="user.address" id="" rows="2" cols="33"></textarea></td></tr><tr><th valign="top">备注信息:</th><td><textarea name="user.remark" rows="3" cols="33"></textarea></td></tr></table></form>
package com.sqb.action;
import java.util.Map;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
import com.sqb.model.User;
import com.sqb.service.UserService;
/**
* 处理用户资料的类,包括个人资料的修改。
* @author Administrator
*
*/
public class UserAction extends ActionSupport implements SessionAware,RequestAware{
private User user;
private Map<String,Object> session;
private Map<String,Object> request;
private UserService userService;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void setSession(Map<String, Object> session) {
this.session = session;
}
public void setRequest(Map<String, Object> request) {
this.request = request;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
/**
* 用于保存修改的信息的方法
*/
@Override
public String execute() throws Exception {
System.out.println("----------------------------");
user.setId(((User)session.get("user")).getId());
System.out.println("------------user:"+user);
System.out.println("------------realname:"+user.getRealname());
userService.save(user);
session.put("user", user); //更新session里的user值
return "success";
}
}
<action name="userAction_*" class="userAction" method="{1}">
<result name="success">${pageContext.request.contextPath}/user.jsp<