关于html与serverlet的问题
serverlet的内容
----------------------------------------------
package showcart;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class showcart extends HttpServlet implements SingleThreadModel {
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);
String[] items = { "电视机 ", "电冰箱 ", "电脑 "};
HttpSession session = request.getSession(true);
Integer itemCount = (Integer) session.getAttribute( "itemCount ");
if (itemCount == null) {
itemCount = new Integer(0);
}
PrintWriter out = null;
try {
out = response.getWriter();
} catch (Exception e) {}
//取得POST上来的表单信息
String[] itemsSelected;
String itemName;
itemsSelected = request.getParameterValues( "item ");
//将选中的商品放入会话对象
if (itemsSelected != null) {
for (int i = 0; i < itemsSelected.length; i++) {
itemName = itemsSelected[i];
itemCount = new Integer(itemCount.intValue() + 1);
session.setAttribute( "Item " + itemCount, itemName);
session.setAttribute( "itemCount ", itemCount);
}
}
//写网页头的HTML
out.println( " <html> ");
out.println( " <head> ");
out.println( " <title> 购物篮里的内容 </title> ");
out.println( " </head> ");
out.println( " <body> ");
out.println( " <center> <h1> 您放在购物篮中的商品是: </h1> </center> ");
//将购物篮的内容写入网页
for (int i = 1; i <= itemCount.intValue(); i++) {
String item = (String) session.getAttribute( "Item " + i);
out.println(items[Integer.parseInt(item)]);
out.println( " <BR> ");
}
out.println( " <hr> <p> </p> <A href=\ "../ShowCart.html\ "> 继续选购 </a> ");
out.println( " </body> ");
out.println( " </html> ");
out.close();
}
//Clean up resources
public void destroy() {
}
}
--------------------------------------
html的内容
-----------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "
"http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 购物篮的实例 </title>
</head>
<body>
<center>
<h1> 电器商场 </h1>
</center>
<hr>
<form action= "ShowCart/showcart " method= "get " name= "form1 "> 先购商品
<p>
<input type= "Checkbox " name= "item " value= "0 ">
第一种:电视机
</p>
<p>
<input type= "Checkbox " name= "item " value= "1 ">
第二种:电冰箱
</p>
<p>
<input type= "Checkbox " name= "item " value= "2 ">
第三种:电脑
</p>
<hr>
<input type= "Submit " name= "btn_submit " value= "加入购物篮 ">
</form>
</body>
</html>
---------------------------------------
应该是先弹出html文档把html处理的结过提交给serverlet,可是为什么无法弹出html的页面?
[解决办法]
log日志看看,