标签:
EncodingServlet.java
1 package cn.jbit.auction.web; 2 3 import java.io.IOException; 4 5 import javax.servlet.ServletException; 6 import javax.servlet.http.HttpServlet; 7 import javax.servlet.http.HttpServletRequest; 8 import javax.servlet.http.HttpServletResponse; 9 10 public class EncodingServlet extends HttpServlet { 11 12 @Override 13 protected void service(HttpServletRequest request, HttpServletResponse response) 14 throws ServletException, IOException { 15 request.setCharacterEncoding("UTF-8"); 16 response.setCharacterEncoding("UTF-8"); 17 super.service(request, response); 18 } 19 20 }
其它的servlet在创建时可以直接继承即可
public class AddAuctionServlet extends EncodingServlet {}
EncodingServlet.java为每一个servlet设置编码方式
标签:
原文地址:http://www.cnblogs.com/jimorulang/p/5557873.html