Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用servlet获取并发送字符串[]数组中的数据 inti=0; 字符串[]pnumbers=新字符串[3]; 字符串[]pqtys=新字符串[3]; 受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应) 抛出ServletException、IOException{ 字符串pnumber=request.getParameter(“pnumber”); DAO=新DAO(); 产品p=dao.checkProduct(产品编号); 字符串qunty=request.getParameter(“pqty”); 而(i_Java_Jsp_Servlets - Fatal编程技术网

Java 使用servlet获取并发送字符串[]数组中的数据 inti=0; 字符串[]pnumbers=新字符串[3]; 字符串[]pqtys=新字符串[3]; 受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应) 抛出ServletException、IOException{ 字符串pnumber=request.getParameter(“pnumber”); DAO=新DAO(); 产品p=dao.checkProduct(产品编号); 字符串qunty=request.getParameter(“pqty”); 而(i

Java 使用servlet获取并发送字符串[]数组中的数据 inti=0; 字符串[]pnumbers=新字符串[3]; 字符串[]pqtys=新字符串[3]; 受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应) 抛出ServletException、IOException{ 字符串pnumber=request.getParameter(“pnumber”); DAO=新DAO(); 产品p=dao.checkProduct(产品编号); 字符串qunty=request.getParameter(“pqty”); 而(i,java,jsp,servlets,Java,Jsp,Servlets,我需要在这个数组中添加3个来自网页的项目。但是你可以添加一项 int i = 0; String[] pnumbers = new String[3]; String[] pqtys = new String[3]; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

我需要在这个数组中添加3个来自网页的项目。但是你可以添加一项

 int i = 0;
 String[] pnumbers = new String[3];
 String[] pqtys = new String[3];

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

 String pnumber = request.getParameter("pnumber");
 DAO dao = new DAO();
 Product p = dao.checkProduct(pnumber);
 String qunty = request.getParameter("pqty");

  while (i < 3) {
  pnumbers[i] = p.getNumber();
  pqtys[i] = p.getQty();
  i++;
  }
request.setAttribute("pnum" pnumbers);
}


我只需要添加3个项目的数组后,添加这3个我需要得到的值再次到同一页请帮助

一旦您在Servlet中像以前一样设置了属性

<td>
<input type="text" name="pnumber" value="" />
</td>
<td>
<input type="text" name="pqty" value="" />
</td>
将控制从Servlet转发到所需的JSP,您可以使用

request.getAttribute(paramName)

提示:

if(request.getAttribute(“pnum”)!=null){
String[]strArray=(String[])request.getAttribute(“pnum”);

对于(int i=0;iyou html代码不使用循环来显示3种产品和数量。您能详细说明您的查询吗?
request.setAttribute("pnum" pnumbers);
if(request.getAttribute("pnum")!=null){
    String []strArray = (String []) request.getAttribute("pnum");
    for(int i=0;i<strArray.length;i++){
         out.println(strArray[i]);
    }
}