当前位置: 代码迷 >> Java Web开发 >> servlet?
  详细解决方案

servlet?

热度:78   发布时间:2016-04-17 15:17:42.0
servlet??
import   javax.servlet.*;
import   javax.servlet.http.*;
import   java.io.*;
import   java.util.*;
public   class   ShowCart   extends   HttpServelt
{
public   void   doPost(HttpServletRequest   req,HttpServletResponse   res)   throws   ServletException,IOException
{
    String[]   items={ "电视机 ", "电冰箱 ", "电脑 "};
    HttpSession   session=req.getSession(true);
    Integer   itemCount=(Integer)session.getValue( "itemCount ");
    if(itemCount==null)
{
            itemCount=new   Integer(0);
    }
    re.setContentType( "text/html;charset=gb2312 ");
    PrintWriter   out=res.getWriter();
    String[]   itemsSelected;
    String   itemName;
    itemsSelected=re.getParameterValues( "item ");
    if(itemsSelected!=null)
{
            for(int   i=0;i <itemsSelected.length;i++)
{
            itemName=itemsSelected[i];
    itemCount=new   Integer(itemCount.intValue()+1);
    session.putValue( "Item "+itemCount,itemName);
    session.putValue( "itemCount ",itemCount);
    }
    }
    out.println( " <html> ");
    out.println( " <head> ");
    out.println( " <title> JSP </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.getValue( "Item "+i);
    out.println(items[Integer.parseInt(item)]);
    out.println( " <br> ");
    }
    out.println( " <hr> <p> </p> <a   href= "\jsp\a.html "> 继续选购 </a> ");
    out.println( " </body> ");
    out.println( " </html> ");
    out.close();
}
}这个文件在我的D:\jsp\WEB-INF\classes里. <html>
<head>
<title> JSP </title>
</head>
<body>
<center> <h1> 电器商场 </h1> </center>
<hr>
<form   action= "/jsp/ShowCart "   method= "post ">
选购商品: <p>
<input   type= "Checkbox "   name= "item "   value= "0 ">
第一种:电视机 </p>
<p> <input   type= "Checkbox "   name= "item "   vlaue= "1 ">
第二种:电冰箱 </p>
<p> <input   type= "Checkbox "   name= "item "   value= "2 ">
第三种:电脑 </p>
<hr>
<input   type= "Submit "   name= "btn_Submit "   value= "加入购物篮 ">
</form>
</body>
</html> 这个文件在D:\jsp里.
请问在ShowCart文件里的 <a   href= "... "> 继续选购 </a> "),href=这里的路径怎么填呀还有 <form   action= "/jsp/ShowCart "   method= "post ">
  相关解决方案