<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'upd.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
var id = ${param.id}
alert(id);
//回显代码
$.ajax({
url:"show!showUpd",
type:"post",
data:{"teacher.id":id},
dataType:"json",
success:function (msg){
$("#id").val(msg.id);
$("#name").val(msg.name);
$("#sex").val(msg.sex);
var hobby = msg.hobby.split(",");
for ( var i in hobby) {
$("[value="+hobby[i].trim()+"]").attr("checked",true);
}
$("#did").val(msg.did);
$("#address").val(msg.address);
}
});
function doupd(){
$.ajax({
url:"show!doUpd",
type:"post",
data:$("form").serialize(),
dataType:"text",
success:function (msg){
if(msg>0){
alert("修改成功");
location="show.action";
}else{
alert("修改失败");
}
}
});
}
</script>
</head>
<body>
<form>
<input type="hidden" name="teacher.id" id="id"><br>
name:<input name="teacher.name" id="name"><br>
sex:<input name="teacher.sex" id="sex"><br>
hobby:<input type="checkbox" name="teacher.hobby" id="hobby" value="喝酒">喝酒
<input type="checkbox" name="teacher.hobby" id="hobby" value="跳舞">跳舞
<input type="checkbox" name="teacher.hobby" id="hobby" value="唱歌">唱歌 <br>
did:<input name="teacher.did" id="did"><br>
address:<input name="teacher.address" id="address"><br>
<input type="button" value="修改" onclick="doupd()">
</form>
</body>
</html>
package com.action;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.alibaba.fastjson.JSONArray;
import com.dto.TeaDep;
import com.dto.Teacher;
import com.service.TeacherService;
import com.util.PageUtils;
public class Action {
//调用service
private TeacherService service = new TeacherService();
List<TeaDep> TeacherList;//集合
PageUtils pu;//工具类
Integer cpage;//页数
String mohu;//模糊条件
Teacher teacher;
//默认调用execute
public String execute() {
// TODO Auto-generated method stub
if(cpage == null){
cpage = 1;
}
Integer pageSize = 2;
//模糊查询
int count = service.count(mohu);
//调用工具类
pu = new PageUtils(cpage, pageSize, count);
TeacherList = service.TeacherList(pu,mohu);
System.out.println(TeacherList);
return "clist";
}
public void showUpd() throws IOException{//抛异常
System.out.println("showupd");
teacher = service.showUpd(teacher);
String jsonString = JSONArray.toJSONString(teacher);
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
response.getWriter().write(jsonString);
}
public void doUpd() throws IOException{//抛异常
System.out.println("doupd");
int i = service.doUpd(teacher);
System.out.println(i);
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
response.getWriter().print(i);
}
//设置setget方法
public String getMohu() {
return mohu;
}
public void setMohu(String mohu) {
this.mohu = mohu;
}
public Integer getCpage() {
return cpage;
}
public void setCpage(Integer cpage) {
this.cpage = cpage;
}
public List<TeaDep> getTeacherList() {
return TeacherList;
}
public void setTeacherList(List<TeaDep> teacherList) {
TeacherList = teacherList;
}
public PageUtils getPu() {
return pu;
}
public void setPu(PageUtils pu) {
this.pu = pu;
}
public Teacher getTeacher() {
return teacher;
}
public void setTeacher(Teacher teacher) {
this.teacher = teacher;
}
}
有些事情是急不来的,等到条件成熟时,自然水到渠成。世界上那些了不起的成就,大多是由耐心堆积而成的。耐心,意味着要经得起眼前的诱惑,耐得住当下的寂寞。耐心不是外在的压抑,而是内心的修行。不要去采摘那些还没有成熟的果实,否则,你的生活一定是苦涩的。
2156

被折叠的 条评论
为什么被折叠?



