jsp中一個頁面引入另一個頁面的實現代碼_JSP編程

來源:互聯網
上載者:User

action程式碼片段

複製代碼 代碼如下:

public String execute() {
        String ret = super.execute();

        if (RETURN_LIST.equals(ret)) {
            return list();
        } else {
            return ret;
        }
    }

    public String list() {
        String show = this.getRequest().getParameter("show");
        if ("show".equals(show)) {
            return show();
        }
        deptid = getRequest().getParameter("deptid");
        if (StringUtils.isNotBlank(deptid)) {
            epVO.getEp().setDeptid(Long.valueOf(deptid));
            epVO.setDeptid(deptid);
        }
        if (StringUtils.isNotBlank(deptname)) {
            epVO.getDept().setDeptname(deptname);
        }
        if (StringUtils.isNotBlank(plateno)) {
            epVO.setPlateno(plateno);
        }
        if (StringUtils.isBlank(deptid)) {
            epVO.getEp().setDeptid(Long.parseLong("1"));
        }

        int count = epService.getEpCount(epVO);
        PageInfor pageInfor = this.pageInit(this.getRequest(), count);
        epVO.setRownum_(pageInfor.getRownum_());
        epVO.setRownum(pageInfor.getRownum());
        epVO.setOrderName(pageInfor.getOrderName());
        List<EpVO> list = epService.getEps(epVO);
        this.getRequest().setAttribute(Constants.QUERY_DATA, list);
        this.getRequest().setAttribute(Constants.PAGE_INFO, pageInfor);

        List<Object> editors = new ArrayList<Object>();
        editors.add(new EditorExt("text", "deptname", "公司"));
        editors.add(new EditorExt("text", "plateno", "車牌號"));
        editors.add(new EditorExt("text", "deptid", "ID"));
        this.getRequest().setAttribute("editor", editors);
        List<Object> header = new ArrayList<Object>();
        List<Object> header = new ArrayList<Object>();
        header.add(new Header("index", "序號", "index", "2%"));//1
        header.add(new Header("epVO.dept.deptname", "部門", null, "6%"));// 2 jQuery(function()中取普通的值 用下標取 下標是它出現的位置
        header.add(new Header("epVO.ep.name", "車牌號", null, "5%"));//3
        header.add(new Header("epVO.ep.epid", "內部編號", null, "5%"));//4
        header.add(new Header("epVO.ep.eptype", "類型", null, "4%"));//5
        header.add(new Header("epVO.ep.devid", "裝置號", null, "8%"));
        header.add(new Header("epVO.ep.devtype", "裝置類型", null, "4%"));
        header.add(new Header("epVO.ep.phone", "電話", null, "5%"));
        header.add(new Header("epVO.ep.charge", "年服務費", null, "5%"));
        header.add(new Header("epVO.ep.info", "備忘", null, "15%"));
        this.getRequest().setAttribute("header", header);
        this.getRequest().setAttribute("header", header);

        Map<String, String> hidden = new LinkedHashMap<String, String>();
        hidden.put("epVO.ep.id", "車輛ID");
        hidden.put("epVO.dept.deptid", "部門ID");//jQuery(function()中取隱藏欄位中的值
        hidden.put("epVO.ep.name", "車牌號");//jQuery(function()中取隱藏欄位中的值
        hidden.put("epVO.ep.eptype", "類型");
        this.getRequest().setAttribute("hidden", hidden);

        String flag = this.getRequest().getParameter("flag");
        this.getRequest().setAttribute("flag", flag);
        return RETURN_LIST;
}

jsp頁面引用程式碼片段

複製代碼 代碼如下:

<%@ 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>
<base target="_self">
<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 src="scripts/DatePicker/WdatePicker.js"></script>
<script src="scripts/Globals.js"></script>
<script src="scripts/DhtmlTree/js/dhtmlxcommon.js"></script>
<script src="scripts/DhtmlTree/js/dhtmlxtree.js"></script>
<link type="text/css" rel="stylesheet"
    href="scripts/DhtmlTree/css/dhtmlxtree.css">
</head>

<body>
    <web:clean editorMeta="editor" />
    <s:hidden name="epVO.deptid" id="deptid" />
    <web:error />
    <div id="query" class="framesytle">
       <!-- 是否在了那個一個頁面中開啟 -->
        <s:if test="#attr.flag=='open'">
            <web:queryTable action="listEp.action?flag=open" editorMeta="editor"
                title="查詢條件" />
            <web:tableList action="listEp.action?method=list&flag=open"
                headerMeta="header" hiddenMeta="hidden" title="查詢結果"
                showlist="hidden" top="false" mode="radio" />
        </s:if>
        <s:else>
            <web:queryTable action="listEp.action" editorMeta="editor"
                title="查詢條件" />
            <web:tableList action="listEp.action?method=list" headerMeta="header"
                hiddenMeta="hidden" title="查詢結果" showlist="hidden" top="false"
                mode="radio" />
        </s:else>
    </div>
</body>
</html>
<script language="JavaScript" type="text/JavaScript">   
    //部門查詢時用到的
    $("#queryBtn").removeAttr('onclick').click(
            function() {
                var obj = document.forms['queryForm'];
                obj.action = '<s:url value="/listEp.action"/>'
                        + '?deptid=' + document.getElementById('deptid').value;
                obj.submit();
            });

    //開啟時頁面要傳遞的值
    jQuery(function() {
        var flag = '<s:property value="#attr.flag" />';
        if (flag == "open") {
            $("#dataTable tr").removeAttr("title").removeAttr("ondblclick");
            jQuery(".all_border .hs tbody tr").attr("title", "雙擊選中");
            jQuery(".all_border .hs tbody tr:gt(0)").removeAttr('ondblclick')
                    .dblclick(
                            function() {
                                //隱藏欄位中取的值 list()中取
                                var name = $(this).find("input[name='name']")
                                        .val();
                                //var deptname = $(this).find("input[name='deptname']").val();
                                var deptid = $(this).find(
                                        "input[name='deptid']").val();
                                //平常的值
                                var deptname = $(this).children().eq(2).text()
                                var info = $(this).children().eq(10).text()
                                        .split(";")[0];
                                if (info == "") {
                                    info = "暫無路線";
                                }
                                var arr = new Array();
                                arr[0] = name;
                                arr[1] = deptname;
                                arr[2] = deptid;
                                arr[3] = info;

                                returnValue = arr;
                                window.close();
                            });
        }
    });

    $(document)
            .ready(
                    function() {
                        var deptname = document.getElementById('deptname').value;
                        var deptid = document.getElementById('deptid').value;
                        var plateno = document.getElementById('plateno').value;

                        $("#queryTable")
                        .html("<tbody><tr class='f1f1f1'><td align='right'>公司:</td><td class='r_border'><input type='text' value='"+deptname+"' id='deptname' name='deptname' class='input_sytle_1'></td><td align='right'>車牌號:</td><td class='r_border'><input type='text' value='"+plateno+"' id='plateno' name='plateno' class='input_sytle_1'><input type='hidden' value='"+deptid+"' id='deptid' name='deptid' class='input_sytle_1'></td></tr></tbody>");
                var tree = initDropDownTree('orgTree',
                        '<s:url value="/commonPage.action?method=getOrgTree"/>');
                setTextBoxTree('deptname', 'deptid', 'orgTree', tree);
                    });
</script>

jsp被引用js程式碼片段

複製代碼 代碼如下:

<script language="JavaScript" type="text/JavaScript">
   //另一個頁面
    // 這個頁面的id個數 是根據另一個頁面傳過來的決定的
    function selPlateno(plateno,deptname,deptid,info)
    {   
        var ret = openWin("listEp.action?method=list&flag=open", "900px", "500px");
        if (ret != undefined) {
            document.getElementById(plateno).value=ret[0];
            document.getElementById(deptname).value=ret[1];
            document.getElementById(deptid).value=ret[2];
            document.getElementById(info).value=ret[3];

        }
    }

    //載入圖片顯示另一個頁面
    $(document).ready(function(){
        //
        $("#plateno").after(" <img onclick=\"selPlateno('plateno','deptname','deptid','info')\" style=\"cursor:hand; vertical-align:text-bottom\" src=\"<s:url value='/images/sel.jpg'/>\" alt=\"選擇\" border=\"0\">");
    });   
</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.