前台页面
<li>
<div class="fc">
<input name="id" type="hidden" id="id"/>
</div>
</li>
<li>
<label class="label">用户名:<span>*</span></label>
<div class="fc">
<input name="name" type="text" maxlength="40" id="name" value="${u.name}" /> <span class="tips">最多40个字符</span>
</div>
</li>
<li>
<label class="label">邮箱:<span>*</span></label>
<div class="fc">
<input name="email" type="text" maxlength="16" id="email" value="${u.email}" /> <span class="tips">最多16个字符</span>
</div>
<script type="text/javascript">
function Preservation(){
alert("点击保存");
var name = $("#name").val();
alert("----用户信息---"+name);
var email = $("#email").val();
alert("---用户邮箱----"+email);
var id = ${u.id}
alert("---用户ID----"+id);
$.ajax({
url:"<%=request.getContextPath()%>/login_update.action",
type:"post",
data:{
"id":id,
"name":name,
"email":email
},
dataType:"json",
success:function(obj){
if(obj){
alert("修改成功!");
location.href = "<%=request.getContextPath()%>/login_toMain.action;
}
else{
alert("修改失败!");
}
}
})
}
后台接收不到值,更新不了数据,/**
* 修改action
* @return
* @throws IOException
* @throws SQLException
*/
public String update() throws SQLException {
//通过ID找对象
UserInfo userInfo = UserInfoDataProvider.getInstance().getUserInfoById(id);
System.out.println("============"+userInfo.getName());
System.out.println("----------------"+userInfo.getId());
//更新
UserInfoDataProvider.getInstance().updateUserInfo(userInfo);
HttpServletResponse response = ServletActionContext.getResponse();
JSONObject json = JSONObject.fromObject(userInfo);
try {
response.getWriter().write(json.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;