1 package com.zhiyuan.servlet;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
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 /**
11 * <p>Title: 响应SERVLET
12 * <p>Company:
13 * @description RespServlet
14 * @author LIANG ZHIYUAN
15 * @date 2016年5月4日下午9:41:00
16 * @version 1.0
17 */
18 public class RespServlet extends HttpServlet {
19
20 /**
21 * 串行号
22 */
23 private static final long serialVersionUID = 4176783017819187776L;
24
25 /**
26 * Constructor of the object.
27 */
28 public RespServlet() {
29 super();
30 }
31
32 /**
33 * Destruction of the servlet. <br>
34 */
35 public void destroy() {
36 super.destroy();
37 }
38
39 public void doGet(HttpServletRequest request, HttpServletResponse response)
40 throws ServletException, IOException {
41 this.doPost(request, response);
42 }
43
44 public void doPost(HttpServletRequest request, HttpServletResponse response)
45 throws ServletException, IOException {
46 request.setCharacterEncoding("utf-8");
47 response.setCharacterEncoding("utf-8");
48 response.setContentType("text/html;charset=utf-8");
49 String content=request.getParameter("data");
50 String str = new String(content.getBytes("ISO-8859-1"),"utf-8");
51 PrintWriter writer=response.getWriter();
52 writer.print(str);
53 System.out.println(str);
54 }
55
56 /**
57 * Initialization of the servlet. <br>
58 *
59 * @throws ServletException if an error occurs
60 */
61 public void init() throws ServletException {
62
63 }
64
65 }
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
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 /**
11 * <p>Title: 响应SERVLET
12 * <p>Company:
13 * @description RespServlet
14 * @author LIANG ZHIYUAN
15 * @date 2016年5月4日下午9:41:00
16 * @version 1.0
17 */
18 public class RespServlet extends HttpServlet {
19
20 /**
21 * 串行号
22 */
23 private static final long serialVersionUID = 4176783017819187776L;
24
25 /**
26 * Constructor of the object.
27 */
28 public RespServlet() {
29 super();
30 }
31
32 /**
33 * Destruction of the servlet. <br>
34 */
35 public void destroy() {
36 super.destroy();
37 }
38
39 public void doGet(HttpServletRequest request, HttpServletResponse response)
40 throws ServletException, IOException {
41 this.doPost(request, response);
42 }
43
44 public void doPost(HttpServletRequest request, HttpServletResponse response)
45 throws ServletException, IOException {
46 request.setCharacterEncoding("utf-8");
47 response.setCharacterEncoding("utf-8");
48 response.setContentType("text/html;charset=utf-8");
49 String content=request.getParameter("data");
50 String str = new String(content.getBytes("ISO-8859-1"),"utf-8");
51 PrintWriter writer=response.getWriter();
52 writer.print(str);
53 System.out.println(str);
54 }
55
56 /**
57 * Initialization of the servlet. <br>
58 *
59 * @throws ServletException if an error occurs
60 */
61 public void init() throws ServletException {
62
63 }
64
65 }