1,表单页面 shangpin.html
1 2 3 4 526 27 28商品信息 6 7 8 9 商品信息10 11
2.接收处理servlet: shp.java
1 package com.hanqi; 2 3 import java.io.IOException; 4 import javax.servlet.ServletException; 5 import javax.servlet.http.HttpServlet; 6 import javax.servlet.http.HttpServletRequest; 7 import javax.servlet.http.HttpServletResponse; 8 9 /**10 * Servlet implementation class Shp11 */12 public class Shp extends HttpServlet {13 private static final long serialVersionUID = 1L;14 15 /**16 * @see HttpServlet#HttpServlet()17 */18 public Shp() {19 super();20 // TODO Auto-generated constructor stub21 }22 23 /**24 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)25 */26 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {27 // TODO Auto-generated method stub28 //指定字符集29 response.setCharacterEncoding("GBK");30 request.setCharacterEncoding("utf-8");31 //获取表单提交信息32 String name = request.getParameter("name");33 String kind = request.getParameter("kind");34 String intr = request.getParameter("intr");35 36 // //Request字符集转换37 // String zname = new String(name.getBytes("iso-8859-1"),"utf-8");38 // String zkind = new String(kind.getBytes("iso-8859-1"),"utf-8");39 // String zintr = new String(intr.getBytes("iso-8859-1"),"utf-8");40 // 41 response.getWriter().append("商品名称:" + name + "; 商品类别:" + kind + "; 商品简介:" + intr);42 43 //response.getWriter().append("Served at: ").append(request.getContextPath());44 }45 46 /**47 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)48 */49 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {50 // TODO Auto-generated method stub51 doGet(request, response);52 // response.setCharacterEncoding("gbk");53 // request.setCharacterEncoding("utf-8");54 // //获取表单提交信息55 // String name = request.getParameter("name");56 // String kind = request.getParameter("kind");57 // String intr = request.getParameter("intr");58 // 59 // response.getWriter().append("商品名称:" + name + "; 商品类别:" + kind + "; 商品简介:" + intr);60 61 }62 63 }