模拟购物车问题
在下写了个简单的购物车,运行后添加商品但是没有显示商品,不知为何?
程序如下:
package ex3_4;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class ShoppingCartViewerHidden 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( "text/html;charset=GBK ");
response.setCharacterEncoding( "GBK ");
PrintWriter out = response.getWriter();
out.println( " <html> ");
out.println( " <head> <title> 当前购物车中的商品 </title> </head> ");
out.println( " </body> ");
request.setCharacterEncoding( "GBK ");//处理中文
//item参数中存储有购物车中的商品
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.print(items[i]);
}