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

jsp action中保存和修改的关系

程序员文章站 2022-10-10 20:04:14
action中的代码片段 复制代码 代码如下:private string epid;//全局变量 得到的是一个以逗号分隔的字符串 public string getep...

action中的代码片段

复制代码 代码如下:

private string epid;//全局变量 得到的是一个以逗号分隔的字符串
public string getepid() {
        return epid;
}

public void setepid(string epid) {
        this.epid = epid;
}

public string edit() {
        try {
            if ("save".equals(save)) {//点击保存按钮的时候执行
                return save();
            } else {
                loadinfo();
                return return_edit;
            }
        } catch (exception e) {
            super.printerrors(this.getrequest(), e, classname);
            return return_error;
        }
}

private void loadinfo() throws exception {
        epid = this.getrequest().getparameter("id");//得到单个的epid
        long userid = getloginuser().getuser().getuserid();
        /**
             功能:
              得到单个对象 并把各个对象 放到vo对象中
              页面中显示数据的值

        **/

        ep ep = new ep();
        ep.setid(long.parselong(epid));
        ep = epservice.getepbyid(ep);
        epvo.setep(ep);
        // depart对象
        depart depart = new depart();
        depart.setdeptid(ep.getdeptid());
        depart.setplatenumber(ep.getname());
        depart.setcreateby(userid);
        depart.setjudgetype(integer.parseint("0"));
        string str[] = ep.getinfo().split(";");
        string s1 = "";
        for (int i = 0; i < str.length; i++) {
            s1 = str[0];
        }

        if ("".equals(s1) || null == s1) {
            depart.setroute("暂无路线");
        } else {
            depart.setroute(s1);
        }
        epvo.setdepart(depart);
        // dept对象
        dept dept = new dept();
        dept = deptservice.getdeptbyid(ep.getdeptid());
        epvo.setdept(dept);

}


    public string save() {

        long deptid = epvo.getdept().getdeptid();
        try {
            depart depart = epvo.getdepart();
            depart.setdeptid(deptid);

            departservice.insertdepart(depart);
            super.printmsg(this.getrequest(), "保存成功!");

            cleanobject();
        } catch (exception e) {
            super.printerrors(this.getrequest(), e, classname);
            return return_error;
        }

        return list();
    }

jap页面

复制代码 代码如下:

<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="/web-inf/web.tld" prefix="web"%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>修改缴费信息信息</title>
        <web:jquery validate="true" formid="tableform" />
        <link type="text/css" rel="stylesheet" href="styles/css.css">
        <script language="javascript" type="text/javascript" src="scripts/datepicker/wdatepicker.js"></script>
        <script language="javascript" type="text/javascript" src="scripts/globals.js"></script>
    </head>
    <body>
        <form action="" method="post" id="tableform" name="tableform">
        <web:error />
        <web:tabletitle name="修改缴费信息信息" />
        <s:hidden name="epvo.dept.deptid" id="deptid" />//隐藏传递过来的值
        <s:hidden name="epvo.depart.createby"  />
        <s:hidden name="id" />
        <div class="table_border">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="hs">

            </table>
        </div>
        <div class="t_center">
            <input id="submitbtn" type="submit" value="保存" style="display: none" />
            <a href="#" class="sava_b b" onclick="save()">保存</a>
        </div>
        </form>
    </body>
</html>

<script language="javascript" type="text/javascript">
    //保存
    function save() {
        var obj = document.getelementbyid("tableform");
        obj.action = '<s:property value="#request.saveurl"/>';
        var submitbtn = document.getelementbyid("submitbtn");
        submitbtn.click();//通过js时间控制提交事件
    }
    //展示
    function query(){
        window.location.href='<s:url value="/listep.action"/>';
    }
    //加载日期控件
    $(document).ready(function(){
        addformvalidator();
        $("#sendtime").attr("readonly","readonly");
        $("#sendtime").click(function(){wdatepicker({isshowclear:false,datefmt:'yyyy-mm-dd hh:mm:ss'});});
    });

</script>