-
[tomcat] URI Encoding (Percent Encoding)tomcat 2024. 9. 25. 23:12
@WebServlet("/test/percentEncoding") public class PercentEncodingServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("=== PercentEncodingServlet.doGet ==="); System.out.println("request = " + request); String username = request.getParameter("username"); System.out.println("username = " + username); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("=== PercentEncodingServlet.doPost ==="); System.out.println("request = " + request); String username = request.getParameter("username"); System.out.println("username = " + username); } }
요청: http://localhost:8080//test/percentEncoding?username=홍길동
(tomcat 10 사용)
별도의 셋팅을 작업하지 않은 경우 한글이 깨지지 않는 이유가? HttpServletRequest.getParameter("username")
-> uri에 포함된 username 쿼리 파라메터에 대한 값을 가져오는 메서드
uri encoding시에 기본적으로 UTF-8을 사용하도록 규약되있음
https://it-eldorado.com/posts/49e57d77-f624-4b2f-880c-cf944a39d92e
URL 인코딩/디코딩 (URL Encoding/Decoding) :: IT 엘도라도
이번 포스팅에서는 URL의 인코딩/디코딩에 대해 간단히 알아볼 것이다. 그런데 이것을 이해하려면 먼저 문자열 인코딩에 대한 배경지식이 있어야 한다. 만약 ASCII, UTF-8의 ...
it-eldorado.com
https://stackoverflow.com/questions/29276432/what-character-set-should-be-used-for-url-encoding
What character set should be used for URL encoding?
I need to encode a URL component. The URL component can contain special character like "?,#,=" and also characters of Chinese language. Which of the character sets should I use: UTF-8, UT...
stackoverflow.com
tomcat/conf/server.xml의 <Connector>의 URIEncoding 속성 값
인코딩된 uri 바이트 데이터를 디코드할때 사용될 인코딩값을 지정하는 속성 https://tomcat.apache.org/tomcat-10.1-doc/config/http.html
Apache Tomcat 10 Configuration Reference (10.1.30) - The HTTP Connector
This Connector supports all of the required features of the HTTP/1.1 protocol, as described in RFCs 7230-7235, including persistent connections, pipelining, expectations and chunked encoding. If the client supports only HTTP/1.0 or HTTP/0.9, the Connector
tomcat.apache.org
별도의 셋팅이 없으면 알아서 encoding decoding이 모두 default로 UTF-8로 설정되어 있기 때문에 한글 사용시 아무 문제가 없이 정상 출력된다.
구버전 tomcat의 경우에는 default값이 UTF-8이 아님 만약 이 값을 다른 charset으로 변경한 후
tomcat/conf/server.xml 톰캣을 실행시켜 위의 요청을 다시 날리게 되면
인코딩시에는 UTF-8로 처리되었지만 tomcat에서 EUC-KR로 디코딩해버려서 한글이 깨지게 됨.
스프링에서 인코딩 관련해서 제공해주는 부분이 많아서 인코딩 관련 개념은 하나씩 정리해나갈 필요가 있는듯하다?