这是我的第一个将内容传递给下一个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时,它只显示更新形式的三星,并且数量显示为空...
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>");
答案 0 :(得分:1)
尝试:
String[] strings = request.getParameterValues("pi")
然后你应该有所有的话
答案 1 :(得分:0)
而不是传递url中的所有参数,为什么不将参数存储在Map
中并将Map
传递给第二个servlet
类似这样的事情
Map map = new HashMap();
while(rs.next())
{
map.put("pi",rs.getString(1));
map.put("pn",rs.getString(2));
map.put("pc",rs.getString(3));
map.put("no",rs.getString(4));
map.put("br",rs.getString(5));
map.put("im",rs.getString(6));
map.put("pr",rs.getInt(7));
map.put("pd",rs.getString(8));
}
request.setAttribute("map", map);
request.getRequestDispatcher("/servleturl").include(request, response);
然后在第二个servlet中从地图中检索值
HashMap map = (HashMap) request.getAttribute("map");
String pi = map.get("pi").toString();