大家谁知道用JSP连接数据库时可以查两张表吗???
谁知道怎么样点了购买后获取前面的字段啊??也就是买了怎么东西,怎么样获取,并把它加到购物篮呢??
可以用隐藏表单域试试,下面是个简单的购物车示例仅供参考:
package shop;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class HiddenServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>当前购物车中的商品</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
request.setCharacterEncoding("GBK");
String[] items=request.getParameterValues("item");
out.println("当前,你的购物车中有这些商品:<br>");
if(items==null){
out.println("<b>商品为空!</b>");
}
else{
out.println("<ul>");
for(int i=0;i<items.length;i++){
out.println("<li>");
out.println(items[i]);
}
out.println("</ul>");
}
out.println("<form action=\"/WebModule1/hiddenservlet\" method=post>");
if(items!=null){
for(int i=0;i<items.length;i++){
out.println("<input type=hidden name=item value=\""+items[i]+"\">");
}
}
int a=new Random().nextInt(100);
out.println("<input type=hidden name=item value=\"商品");
out.println(String.valueOf(a));
out.println("\">");
out.println("您愿意<br>");
out.println("<input type=submit value=\"添加商品\">");
out.println("</body>");
out.println("</html>");
out.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}