jsp action中保存和修改的关系

编程学习 2021-07-05 11:23www.dzhlxh.cn编程入门
这篇文章主要是为大家介绍了jsp中通过action保存与修改的判断方法,学习jsp的朋友可以参考下

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>

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板