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

jsp中一个页面引入另一个页面的实现代码

程序员文章站 2023-01-03 22:52:25
action代码片段 复制代码 代码如下:public string execute() {      &nb...

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>