171114 doGet(), doPost() - RYUDONGJIN/Memo_wiki GitHub Wiki
- ๋ณด์์ ์ทจ์ฝ
- Get๋ฐฉ์ ์์ฒญ ํ๊ธ์ฒ๋ฆฌ <server.xml> ์์
<Connector URIEncoding="UTF-8">
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("doGet");
response.setContentType("text/html; charset=UTF-8");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head>");
writer.println("</head>");
writer.println("<body>");
writer.println("HelloWorld!");
writer.println("</body>");
writer.println("</html>");
writer.close();
}
- ๋ณด์์ ๊ฐ์
- formํํฌ์ ์ ๋ฌ๋ฐฉ์(method)์ด post์ผ ๋ ๋์ํ๋ค.
- Post๋ฐฉ์ ์์ฒญ ํ๊ธ์ฒ๋ฆฌ
request.setCharacterEncoding() ๋ฉ์๋ ์ด์ฉ
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("doPost");
response.setContentType("text/html; charset=UTF-8");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head>");
writer.println("</head>");
writer.println("<body>");
writer.println("<h1>POST๋ฐฉ์์
๋๋ค. doPost() ํธ์ถ</h1>");
writer.println("</body>");
writer.println("</html>");
writer.close();
}