171114 doGet(), doPost() - RYUDONGJIN/Memo_wiki GitHub Wiki

doGet()

  • ๋ณด์•ˆ์— ์ทจ์•ฝ
  • 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();
	}

doPost()

  • ๋ณด์•ˆ์— ๊ฐ•์ 
  • 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();
	}
โš ๏ธ **GitHub.com Fallback** โš ๏ธ