Demo entry 6720651

a

   

Submitted by anonymous on Mar 17, 2018 at 08:01
Language: Java. Code size: 2.3 kB.

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
	response.setContentType("text/html;charset=UTF-8");
	request.setCharacterEncoding("UTF-8");
	PrintWriter out = response.getWriter();
	StringBuffer str = new StringBuffer();
	Mgoods Mg = new Mgoods();
	HttpSession hs = request.getSession(true);
	hs.setAttribute("showgoodsbean", Mg);
	String key = request.getParameter("key");
	if (key.equals("all")) {
		try {
			Statement sta = DBCon.Con().createStatement();
			ResultSet rs = sta.executeQuery("select * from goods");
			str.append("<form action = Ccar method=post> target=\"id_iframe\" ");
			str.append("<table border=1>");
			while (rs.next()) {
				String s = "<a href=Cshowdetail?key=" + rs.getString(1) + "><img src= " + rs.getString(5) + " width=190 height=190 /></a>";
				str.append("<div>" + s  + "</div>");
				str.append("<div>"  + rs.getString(4) + "</div>");
				str.append("<div>" + "<a href=Cshowdetail?key=" + rs.getString(1) + ">" + rs.getString(2) + "</a>"+"</div>");
				str.append("<div>"+"<a href=Ccar?key="+rs.getString(1)+">"+"<input type=\"button\" value=\"加入购物车\">"+"</a>"+"</div>");
			}
			str.append("</form>");
			Mg.setQueryResult(str);
		}
		catch (Exception e) {
			str.append(e);
		}
	} else {
		try {
			Statement sta = DBCon.Con().createStatement();
			ResultSet rs = sta.executeQuery("select * from goods where goodsid like '%" + key + "%'");
			str.append("<form action = Ccar method=post target=\"id_iframe\" >");
			while (rs.next()) {
				String s = "<a href=Cshowdetail?key=" + rs.getString(1) + "><img src= " + rs.getString(5) + " width=190 height=190 /></a>";
				str.append("<div>"  + s + "</div>");
				str.append("<div>" + rs.getString(4)  + "</div>");
				str.append("<div>" + "<a href=Cshowdetail?key=" + rs.getString(1) + ">" + rs.getString(2) + "</a>"+"</div>");
				str.append("<div>"+"<a href=Ccar?key="+rs.getString(1)+">"+"<input type=\"button\" value=\"加入购物车\">"+"</a>"+"</div>");
			}
			str.append("</form>");
			Mg.setQueryResult(str);
		}
		catch (Exception e) {
			str.append(e);
		}
	}
	RequestDispatcher dis = request.getRequestDispatcher("goods.jsp");
	dis.forward(request, response);
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).