xeo_009
2017-08-17 07:28
采纳率: 100%
浏览 2.8k
已采纳

jsp与servlet数组怎么传值接收

function se(){ var stno=document.getElementById("date1").value; var stno1=document.getElementById("date2").value; var stno2=document.getElementById("year1").value; var stno3=document.getElementById("month1").value; var stno4=document.getElementById("man").value; window.location="${pageContext.request.contextPath}/servlet/GrowthOwnerServlet?stno="+stno+"&stno1="+stno1+"&stno2="+stno2+"&stno3="+stno3+"&stno4="+stno4+""; } function se1(){ var stno=document.getElementById("date1").value; var stno1=document.getElementById("date2").value; var stno2=document.getElementById("year1").value; var stno3=document.getElementById("month1").value; var stno4=document.getElementById("man").value; window.location="${pageContext.request.contextPath}/servlet/GrowthOwnerExcel?stno="+stno+"&stno1="+stno1+"&stno2="+stno2+"&stno3="+stno3+"&stno4="+stno4+""; } function checkAll(field) { var selectFlags = document.getElementsByName("selectFlag"); for (var i=0; i<selectFlags.length; i++) { selectFlags[i].checked = field.checked; } } function see(){ var stno=document.getElementById("date1").value; var stno1=document.getElementById("date2").value; var stno2=document.getElementById("year1").value; var stno3=document.getElementById("month1").value; var stno4=document.getElementById("man").value; var selectFlags=[]; var selectFlags = document.getElementsByName("selectFlag"); var flag = false; for (var i=0; i<selectFlags.length; i++) { if (selectFlags[i].checked) { flag = true; break; } } alert(selectFlags); window.location="${pageContext.request.contextPath}/servlet/GrowthOwnersServlet?stno="+stno+"&stno1="+stno1+"&stno2="+stno2+"&stno3="+stno3+"&stno4="+stno4+"&selectFlags="+selectFlags+""; }
</head>

<body class="body1">
    <form name="matterForm" id="matterForm" >

              <div align="left" >
            需求日期<input type="text" id="date1" name="date1" onclick="new Calendar().show(this);"  value="${date1}" readonly="true" autocomplete="off"  />
            <input type="text" id="date2" name="date2" onclick="new Calendar().show(this);"  value="${date2}" readonly="true" autocomplete="off"  /> 
            需求年月<select name="year1" id="year1" onchange="onselectd();">

                        <option value="2017">2017年</option>
                        <option value="2018">2018年</option>
                        <option value="2019">2019年</option>
                        <option value="2020">2020年</option>
                         <option value="2021">2021年</option>
                          <option value="2022">2022年</option>
                           <option value="2023">2023年</option>

                         </select>
                   <select name="month1" id="month1"  onchange="onselectd();">
                        <option value="01">1月</option>
                        <option value="02">2月</option>
                        <option value="03">3月</option>
                        <option value="04">4月</option>
                        <option value="05">5月</option>
                        <option value="06">6月</option>
                        <option value="07">7月</option>
                        <option value="08">8月</option>
                        <option value="09">9月</option>
                        <option value="10">10月</option> 
                        <option value="11">11月</option>
                        <option value="12">12月</option> 

                    </select>
                店面区域范围<select name="man" id="man"  onchange="onselectd();">
                        <option value="222104112">孙xx</option>
                        <option value="222104360">张xx</option>
                        <option value="222103816">谌xx</option>
                        <option value="222103226">刘xx</option>
                        <option value="222104891">罗xx</option>
                        <option value="111222333">管xx</option>                            

                    </select>

               <c:forEach items="${fault}" var="i">
                <tr>
                    <td width="37" class="rd8">
                        <input name="selectFlag" type="checkbox" class="checkbox1"
                            id="selectFlag" value="${i.shopid}">
                    </td>

                    <td width="100" class="rd8">
                        <c:out value="${i.shopid}"></c:out>
                    </td>
                </tr>
                </c:forEach>                                      

             </div> 

后台servlet部分

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("text/html;charset=utf-8");


    String date1=request.getParameter("stno");
    String date2=request.getParameter("stno1");
    String year1=request.getParameter("stno2");
    String month1=request.getParameter("stno3");
    String man=request.getParameter("stno4");

    String [] ss=  request.getParameterValues("selectFlags");

// System.out.println(date1);
// System.out.println(man);
// System.out.println(ss);

    DataManage mn=new DataManage();
    request.getSession().setAttribute("date1", date1);
    request.getSession().setAttribute("date2", date2);
    request.getSession().setAttribute("year1", year1);
    request.getSession().setAttribute("month1", month1);



    request.setAttribute("qc",mn.getGrowthOwners(date1,date2,year1,month1,man,ss));
    request.getRequestDispatcher("/page/model/alliance/growthOwner.jsp").forward(request, response);    

}

service 里的方法

    public List<GrowthOwner> getGrowthOwners(String date1,String date2,String year1,String month1,String man,String[] ss){
            List<GrowthOwner> pre=new ArrayList<GrowthOwner>();
            Connection cn=null;
            PreparedStatement pr=null;
            ResultSet rs=null;
            try {
                cn=getConnection();
                pr=cn.prepareCall("{ call  companyreport.[dbo].[店成长率报表_个人] (?,?,?,?,?)}");
                pr.setString(1,date1);
                pr.setString(2,date2);
                pr.setString(3, year1+"-"+month1);
                pr.setString(4,man);
                pr.setString(5, ss);
                rs=pr.executeQuery();
                while(rs.next()){
                    pre.add(new GrowthOwner(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10),
                            rs.getString(11),rs.getString(12),rs.getString(13),rs.getString(14),rs.getString(15)));
                }                                           
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally{
                try {
                    rs.close();
                    pr.close();
                    cn.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }                   
            }                       
            return pre;
        }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • googleoyyp 2017-08-17 08:35
    已采纳

    1.用字符串拼接来 2.封装成json

    点赞 评论
  • 鼠小 2017-08-17 09:30

    你的问题还算是比较初级,,看看这篇博客很详细:
    http://blog.csdn.net/ssy_shandong/article/details/9328985/

    点赞 评论

相关推荐 更多相似问题