Jsp-Servlet

html -> servlet 전송시 한글깨짐 해결(이클립스)

상류사회 2011. 12. 28. 01:10

 

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Hello extends HttpServlet {
 private static final long serialVersionUID = 1L;

 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
  response.setContentType("text/html; charset=EUC-KR");
  PrintWriter out = response.getWriter();

  request.setCharacterEncoding("EUC-KR");                 // 한줄 삽입으로 한글 깨짐 문제 해결
  
  String id = request.getParameter("userid");
  
  out.print("<html>");
  out.print("<head>");
  out.print("<title></title>");
  out.print("</head>");
  out.print("<body>");
  out.print(id);
  out.print("님의 \t 방문을 환영합니다.");
  out.print("</body>");
  out.print("</html>");
  out.close();
 }