개발자/JSP
httpclient post 전송시 한글깨짐 현상
김진리
2013. 4. 18. 09:33
java 에서 httpclient 를 이용하여 데이터를 보낼시 한글이 ?? 로 깨지는 경우가 발생한다.
한글 처리는 java.net 의 URLEncoder 와 URLDecoder 를 이용해 보낼땐 encode, 받을땐 decode 를 하면 한글이 정상 처리됨을 볼 수 있다.
httpclient file post 방식 예제 )
PostMethod post = new PostMethod("보낼경로");
String filename = URLEncoder.encode("파일이름");
File file = new file(파일경로);
Part[] parts = { new StringPart("보낼 속성 이름",filename),
new FilePart("보낼 속성 이름",file)
};
post.setRequestEntity( new MultipartRequestEntity(parts,filePost.getParams()));
HttpClient client = new httpClient();
int status = client.executeMethod(post); <- 실제적으로 경로를 실행하게되고 상태 값이 int status 에 저장하게 된다 200 이 return 되면 성공 404 는 페이지를 찾을수 없다
if( status == HttpStatus.SC_OK) {
200
}
받을시
String temp = URLDecoder.decode( request.getparameter("속성이름"));
한글 파일 이름이 저장이 된다.