5月28日 CMS 周一

<%@ 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;
    }


}

有些事情是急不来的,等到条件成熟时,自然水到渠成。世界上那些了不起的成就,大多是由耐心堆积而成的。耐心,意味着要经得起眼前的诱惑,耐得住当下的寂寞。耐心不是外在的压抑,而是内心的修行。不要去采摘那些还没有成熟的果实,否则,你的生活一定是苦涩的。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值