123456789101112131415161718192021222324 |
- package com.lovecoding.servlet;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- public class HttpDemoServlet extends HttpServlet{
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.addHeader("Content-Type","text/html;charset=utf-8");
- resp.setCharacterEncoding("UTF-8");
- resp.getWriter().print("<html> <body><h1> 你好 HttpServlet </h1></body> </html>");
- }
- protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.addHeader("Content-Type","text/html;charset=utf-8");
- resp.setCharacterEncoding("UTF-8");
- resp.getWriter().print("你好 HttpServlet");
- }
- }
|