jsp action中儲存和修改的關係_JSP編程

來源:互聯網
上載者:User

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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.