<body>
This is my HTML page. <br>
<a href="/CookieDemo/servlet/CookieDemo2?name=电视机">电视机</a>
<a href="/CookieDemo/servlet/CookieDemo2?name=电冰箱">电冰箱</a>
<a href="/CookieDemo/servlet/CookieDemo2?name=微波炉">微波炉</a><br/>
<form action="/CookieDemo/servlet/CookieDemo3">
<input type="submit" value="结账" />
</form>
</body>
</html>
servlet1代码:
public class CookieDemo2 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//接受html请求过来的参数数据
String name = request.getParameter("name");
//将数据进行先编码在解码过程,解决乱码
name = new String(name.getBytes("iso8859-1"),"utf-8");
response.getWriter().write("您选择了商品"+name);