欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

jq

程序员文章站 2022-07-15 07:52:46
...
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
        <title></title>
    </head>
    <style>
    .err{
        color:red
    }
    .ok{
        color:green
    }
    </style>
    <script type="text/javascript">
        $(function(){
            $.post(
                //请求路径
                "http://localhost:8090/TestWeb03/ajax01",
                //往后台传数据
                $("#form01").serialize(),
                //响应处理方法,data形参值为响应的json字符串
                function(data){
                    //json字符串转js对象
                    data = JSON.parse(data);
                    $("#a").val(data.showDate);
                    $("#b").val(data.showAmPm);
                }
            );
        });
    </script>
    <body>
    <form id="form01">
    姓名:<input type="text" name="name" id="a" readonly="readonly"><span id="nameMsg"></span><br>
    密码:<input type="text" name="password" id="b" readonly="readonly"><br>
    </form>
    </body>
</html>

public class RegisterInfo {
    private String showDate;
    private String showAmPm;
    public String getShowDate() {
        return showDate;
    }
    public void setShowDate(String showDate) {
        this.showDate = showDate;
    }
    public String getShowAmPm() {
        return showAmPm;
    }
    public void setShowAmPm(String showAmPm) {
        this.showAmPm = showAmPm;
    }
}
public class RegisterService {
    public RegisterInfo getInitRegister(){
        RegisterInfo r = new RegisterInfo();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String s = sdf.format(Calendar.getInstance().getTime());
        r.setShowDate(s);       
        int a = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
        if(a<12){
            r.setShowAmPm("上午");
        }else{
            r.setShowAmPm("下午");
        }
        return r;
    }
}

转载于:https://www.jianshu.com/p/2d2b2a8dfd3e