servlet向jsp传值,开始传不过去,后来页面都跳不过去了
publicclassCountOrderextendsHttpServlet{publicvoiddoPost(HttpServletRequestrequest,Ht...
public class CountOrder extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html;charset=gb2312");
OrderDao dao = new OrderDao();
ArrayList<OrderBean> orderList = dao.selectOrder();
String[] res = new String[orderList.size()*4];
for(int i=0;i<orderList.size();i++){
res[i*4]=orderList.get(i).getOno();
res[i*4+1]=orderList.get(i).getOcustNo();
res[i*4+2]=orderList.get(i).getOmoney();
res[i*4+3]=orderList.get(i).getOtime();
}
request.setAttribute("result", res);
RequestDispatcher view = request.getRequestDispatcher("/OrderManage/CountOrder.jsp");
view.forward(request, response);
}
}
jsp界面,为测试随便写的
<%@ page contentType="text/html;charset = gb2312" %>
<html>
<body>
<% String[] result = (String[])request.getAttribute("result"); %>
<%= result.length %>
</body>
</html> 展开
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html;charset=gb2312");
OrderDao dao = new OrderDao();
ArrayList<OrderBean> orderList = dao.selectOrder();
String[] res = new String[orderList.size()*4];
for(int i=0;i<orderList.size();i++){
res[i*4]=orderList.get(i).getOno();
res[i*4+1]=orderList.get(i).getOcustNo();
res[i*4+2]=orderList.get(i).getOmoney();
res[i*4+3]=orderList.get(i).getOtime();
}
request.setAttribute("result", res);
RequestDispatcher view = request.getRequestDispatcher("/OrderManage/CountOrder.jsp");
view.forward(request, response);
}
}
jsp界面,为测试随便写的
<%@ page contentType="text/html;charset = gb2312" %>
<html>
<body>
<% String[] result = (String[])request.getAttribute("result"); %>
<%= result.length %>
</body>
</html> 展开
1个回答
展开全部
你确定你ArrayList<OrderBean> orderList = dao.selectOrder(); orderLIst能查到数据吗
更多追问追答
追问
直接确定res[ ]的值也没办法传过去
追答
所以你调试的时候res里面是有值的吗?然后通过request.getRequestDispatcher("/OrderManage/CountOrder.jsp").forward(request, response);不能到达CountOrder.jsp是这样吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询