gpt4 book ai didi

java - request.getparameter 没有给出字符串数组的正确答案

转载 作者:行者123 更新时间:2023-12-01 12:44:30 24 4
gpt4 key购买 nike

这是我的第一个 servlet,它将内容传递给下一个 servlet..

    response.setContentType("text/html");
PrintWriter out=response.getWriter();

String s1=request.getParameter("t123");
String s2=request.getParameter("t2");

try
{
Connection conn=dao.DataDAP.getConn();
PreparedStatement ps=conn.prepareStatement("select * from "+s1+" where Brand like '%"+s2+"%'");

ResultSet rs=ps.executeQuery();


out.println("<html><body><center>");
out.println("<h1>Searched Products</h1>");
out.println("<hr>");

out.println("<table border=5>");

out.println("<tr>");
out.println("<td>Product Id</td>");
out.println("<td>Product Name</td>");
out.println("<td>Product Category</td>");
out.println("<td>No. Of Items</td>");
out.println("<td>Brand</td>");
out.println("<td>Image</td>");
out.println("<td>Price</td>");
out.println("<td>Description</td>");
out.println("</tr>");



while(rs.next())
{
String pi=rs.getString(1);
String pn=rs.getString(2);
String pc=rs.getString(3);
String no=rs.getString(4);
String br=rs.getString(5);
String im=rs.getString(6);
int pr=rs.getInt(7);
String pd=rs.getString(8);

out.println("<tr>");
out.println("<td>"+pi+"</td>");
out.println("<td>"+pn+"</td>");
out.println("<td>"+pc+"</td>");
out.println("<td>"+no+"</td>");
out.println("<td>"+br+"</td>");
out.println("<td>"+im+"</td>");
out.println("<td>"+pr+"</td>");
out.println("<td>"+pd+"</td>");

out.println("<td><a href='update?pi="+pi+"&&pn="+pn+"&&pc="+pc+"&&no="+no+"&&br="+br+"&&im="+im+"&&pr"+pr+"&&pd="+pd+"&&table="+s1+"'>Update Product</a></td>");
out.println("</tr>");
}


out.println("</table>");


out.println("</center></body></html>");

}

catch(Exception e)
{
System.out.println(e);
}



}


}

我正在下一个 servlet 中获取所有数据,但是当产品名称为 samsung Galaxy grand2 时,它仅以更新形式显示 samsung,并且在数量上显示为 null...

        response.setContentType("text/html");
PrintWriter out=response.getWriter();

String productid=request.getParameter("pi");
String productname=request.getParameter("pn");
String productcategory=request.getParameter("pc");
String noofitems=request.getParameter("no");
String brand=request.getParameter("br");
String productimage=request.getParameter("im");
String productamount=request.getParameter("pr");
String productdescription=request.getParameter("pd");
String table=request.getParameter("table");


out.println("<html><body><center><h1>Update Form</h1>");

out.println("<form action=update2>");

out.println("<table>");

out.println("<tr>");
out.println("<td>Product ID: </td>");
out.println("<td><input type=text name=t1 value="+productid+" disabled=disabled></td>");
out.println("<input type=hidden name=t1 value="+productid+">");
out.println("</tr>");

out.println("<tr>");
out.println("<td>Product Name: </td>");
out.println("<td><input type=text name=t2 value="+productname+" ></td>");

out.println("</tr>");

out.println("<tr>");
out.println("<td>Product Category: </td>");
out.println("<td><input type=text name=t3 value="+productcategory+" disabled=disabled></td>");
out.println("<input type=hidden name=t3 value="+productcategory+">");
out.println("</tr>");

out.println("<tr>");
out.println("<td>No. of Items: </td>");
out.println("<td><input type=text name=t4 value="+noofitems+"></td>");
out.println("</tr>");

out.println("<tr>");
out.println("<td>Brand: </td>");
out.println("<td><input type=text name=t5 value="+brand+" disabled=disabled></td>");
out.println("<input type=hidden name=t5 value="+brand+">");
out.println("</tr>");

out.println("<tr>");
out.println("<td>Product Image: </td>");
out.println("<td><input type=text name=t6 value="+productimage+" disabled=disabled></td>");
out.println("<input type=hidden name=t6 value="+productimage+">");
out.println("</tr>");

out.println("<tr>");
out.println("<td>Product Amount: </td>");
out.println("<td><input type=text name=t7 value="+productamount+"></td>");
out.println("</tr>");

out.println("<tr>");
out.println("<td>Product Description: </td>");
out.println("<td><textarea style=height:150px;width:200px; name=t8 value="+productdescription+"</textarea> disabled=disabled></td>");
out.println("<input type=hidden name=t8 value="+productdescription+"></textarea>");
out.println("</tr>");

out.println("<tr>");
out.println("<td><input type=submit value=Update></td>");
out.println("</tr>");

out.println("<input type=hidden name=t9 value="+table+">");

out.println("</table>");

out.println("</form>");

out.println("</center></body></html>");

最佳答案

尝试:

String[] strings = request.getParameterValues("pi")
然后你应该拥有所有的单词

关于java - request.getparameter 没有给出字符串数组的正确答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24827787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com