@WebServlet(urlPatterns = "/")public class HelloServlet extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String name = req.getParameter("name"); // 设置响应类型: resp.setContentType("text/html"); // 获取输出流: PrintWriter pw = resp.getWriter(); // 写入响应: String response = String.format("<h1>hello,%s</h1>", name); pw.write(response); pw.write("<h1>Hello, world!</h1>"); // 最后不要忘记flush强制输出: pw.flush(); }}
Sign in to make a reply
。。。