JSP页面通过EL获取后台request中的值

eason1314 发布于 2016/04/01 17:47
阅读 8K+
收藏 0

JSP页面代码为:


<%@ page language="java" import="java.util.*,model.Entt,model.entts.*" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/tld/page.tld" prefix="p"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
    <title>提交情况统计</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache,must-revalidate">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
		
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/easyui/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/easyui/themes/icon.css"/>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/easyui/demo.css"/>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('#submitStatisticsListGrid').width(document.body.clientWidth);
        $('#submitStatisticsListGrid').height(document.body.clientHeight); 
        $('#submitStatisticsListGrid').treegrid({		
            pagination:true,
            pageList:[10,20,30],
            pageSize:10,
            pageNumber:1,  
            rownumbers:false,
            singleSelect:true,
            striped:true,
            loadMsg:'请稍等,数据加载中...',
            method:'post',
            idField: 'buildoffice',
            treeField: 'buildoffice',
            initialState:'collapsed',
            onContextMenu: onContextMenu,
            toolbar:'#submitScheduleListToolbar',
            onLoadSuccess:function(data){
            },
        });
    })
    function onContextMenu(){
			
    }
    function doQuery(vpageNumber,vpageSize){
        $("#fl").form("submit",{
            url:'<%=request.getContextPath() %>/StatisticsSubmitScheduleService',
            onSubmit:function(param){
                param.pageNumber = vpageNumber;
                param.pageSize = vpageSize;
                return $(this).form('enableValidation').form('validate');
            },
            success:function(data){
                alert("${requestScope.description}");
                alert(${requestScope.dws});
                //data = eval('(' + data + ')');
                //data = $.parseJSON(data);
                //$('#submitStatisticsListGrid').treegrid('loadData',{"total" : data.total,"rows" : data.rows}); 
                var pager = $('#submitStatisticsListGrid').treegrid('getPager');
                $(pager).pagination({  
                    pageNumber:vpageNumber,
                    pageSize:vpageSize,
                    total:data.total,
                    beforePageText: '第',//页数文本框前显示的汉字 
                    afterPageText: '页    共 {pages} 页',
                    displayMsg: '共{total}条数据',  
                    onBeforeRefresh: function(){  
                    },  
                    onSelectPage: function (pageNumber, pageSize){//分页触发  
                        doQuery(pageNumber,pageSize);  
                    }  
                });  
                $('#submitStatisticsListGrid').treegrid('collapseAll');
                $('#loadDataWindow').window('close');
            }
        });
    }
</script>
</head>
  		
<body>
    <table id="submitStatisticsListGrid" title=${jdnd}年${themonth}月进度提交情况统计 class="easyui-datagrid" style="width: auto;height:auto;">
        <thead>
            <tr>
                <th data-options="field:'id',align:'center',resizable:false,hidden:true" width=0px>id</th>
                <th data-options="field:'buildoffice',align:'center',resizable:true" width=250px>单位名称</th>
                <th data-options="field:'all',align:'center',resizable:true" width=150px>项目总数</th>
                <th data-options="field:'finished',align:'center',resizable:true" width=150px>已填报项目个数</th>
                <th data-options="field:'unfinished',align:'center',resizable:true" width=150px>未填报项目个数</th>
            </tr>
        </thead>
    <tbody id="tbodyt">
        <c:set var="i" value="0" ></c:set>
        <c:forEach items="${requestScope.dws}" var="dw">
            <tr id="tr${i}">
                <td>${dw}</td>	
                <td name="all" value="${all[dw]}.${i}">${requestScope.all[dw]}</td>
                <td name="finished" value="${empty finished[dw]?0:finished[dw]}.${i}">${empty finished[dw]?0:finished[dw]}</td>	
                <td name="unfinished" value="${empty unfinished[dw]?0:unfinished[dw]}.${i}">${empty unfinished[dw]?0:unfinished[dw]}</td>
            </tr> 
        <c:set var="i" value="${i+1}" ></c:set>
        </c:forEach>
    </tbody>
    <tfoot>
        <tr>
            <td>合计</td>	
            <td>${requestScope.allSum}</td>
            <td>${requestScope.finishedSum}</td>	
            <td>${requestScope.unfinishedSum}</td>
        </tr>
        <tr>
            <td rowspan="4" align="justify"></td>
        </tr>
        <tr>
            <td id="description" rowspan="4" align="left">
                ${requestScope.description}
            </td>
        </tr>
    </tfoot>
    </table>
    </body>
</html>
后台代码为:


public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        HttpSession session = request.getSession();
        HtUser htUser = (HtUser)session.getAttribute("context_entt_e_xt_yong_hu");
        if (htUser == null)
        {
            response.sendRedirect("dl");
            return;
        }
      
        String jsonCondition = "from t_yw_xmmx where projecttype!='99' and splitState = '5'";
        String nd = request.getParameter("nd");
        String jdnd = request.getParameter("jdnd");
        if(nd == null){
            nd = EnttDAO.getCurNd();
        }
        if(jdnd == null){
            jdnd = EnttDAO.getCurNd();
        }
        String theMonth = request.getParameter("themonth");
        String companytype = request.getParameter("companytype");
        String sec_flag = request.getParameter("sec_flag");
        String[] xmlb = request.getParameterValues("input_query_projecttype");
        String batchnumber = request.getParameter("batchnumber");
        String managetype = request.getParameter("managetype");
        Calendar cal = Calendar.getInstance();
        if (theMonth == null) {
            theMonth = (cal.get(Calendar.MONTH) + 1) + "";
        }
        if (managetype != null && !managetype.trim().equals("")) {
            jsonCondition += " and managetype = '" + managetype.trim() + "'";
        }else {
            jsonCondition += " and managetype = 'normal'";
        }
        if (nd != null && !nd.trim().equals("")) {
            jsonCondition += " and to_char(opentime,'yyyy') = '"+ nd + "'";
        }
        if (companytype != null && !companytype.trim().equals("")) {
            jsonCondition += " and companytype = '" + companytype + "'";
        }
        if (sec_flag != null && !sec_flag.equals("")){
            jsonCondition += " and sec_flag = '" + sec_flag + "'";
        }
        if (batchnumber != null && !batchnumber.trim().equals("")) {
            jsonCondition += " and batchnumber = " + batchnumber + " ";
        }
        if (xmlb != null && xmlb.length > 0) {
            String strTemp = "";
            for (String str : xmlb){
                strTemp += " projecttype = '" + str + "' or";
            }
            if (strTemp.endsWith("or")) {
                strTemp = strTemp.substring(0, strTemp.lastIndexOf("or"));
                jsonCondition += " and (" + strTemp + ")"; 
            }
            request.setAttribute("projecttypes", strTemp);
        }
    Map<Integer, Integer> maxBatchNumbers = getMaxBatchNumber();
    request.setAttribute("maxBatchNumbers", maxBatchNumbers);
    if (nd != null && !nd.trim().equals("")) {
        request.setAttribute("presentMaxBatchNumber", maxBatchNumbers.get(Integer.parseInt(nd)));
    }
    Integer b = maxBatchNumbers.get(Integer.parseInt(nd));
    if ((batchnumber == null || batchnumber.trim().equals("")) && b != null && b > 0) {
        jsonCondition += " and batchnumber = " + maxBatchNumbers.get(Integer.parseInt(nd)) + " ";
        batchnumber = b.toString();
    }
    request.setAttribute("batchnumber", batchnumber);
    String monthplanCondition = " nd = '" + jdnd + "' and themonth = " + theMonth;
    Map<String, Integer> all = pdao.StatisticsSubmitSchedule("all", jsonCondition, monthplanCondition);
    Map<String, Integer> finished = pdao.StatisticsSubmitSchedule("finished", jsonCondition, monthplanCondition);
    Map<String, Integer> unfinished = pdao.StatisticsSubmitSchedule("unfinished", jsonCondition, monthplanCondition);
    int allSum = 0;
    int finishedSum = 0;
    int unfinishedSum = 0;
    for (Integer val : all.values()) {
        allSum += val;
    }
    for (Integer val : finished.values()) {
        finishedSum += val;
    }
    for (Integer val : unfinished.values()) {
        unfinishedSum += val;
    }
    String description=getStatisticsDescription(finishedSum,unfinishedSum,unfinished);
    System.out.println("description: "+description);
    request.setAttribute("nd", nd);
    request.setAttribute("jdnd", jdnd);
    request.setAttribute("themonth", theMonth);
    request.setAttribute("companytype", companytype);
    request.setAttribute("sec_flag", sec_flag);
    request.setAttribute("dws", all.keySet());
    request.setAttribute("all", all);
    request.setAttribute("finished", finished);
    request.setAttribute("unfinished", unfinished);
    request.setAttribute("allSum", allSum);
    request.setAttribute("finishedSum", finishedSum);
    request.setAttribute("unfinishedSum", unfinishedSum);
    request.setAttribute("description", description);
    request.setAttribute("managetypeValue", managetype);
    request.getRequestDispatcher("/view/zongHeFenXi/submitScheduleStatistics.jsp").forward(request, response);
}
当输入条件进行查询时,后台输出的"description"结果为:

而在JSP页面通过alert("${requestScope.description}")弹出的结果为:

不管输入什么查询条件,JSP页面通过alert弹出的结果都是上面那张图的结果,请问各位大神这是咋回事呢?谢谢!!!

加载中
0
螃蟹大叔
螃蟹大叔
你在ajax里面去弹,你这是取得进入这个页面的requestScope.description的值,肯定永远都是你进入页面的那个值呀
螃蟹大叔
螃蟹大叔
回复 @eason1314 : 你代码真的不全,不晓得你请求页面的接口和ajax请求的接口是不是同一个,所以不晓得怎么帮你改
e
eason1314
应该怎么改呢?谢谢!
返回顶部
顶部