SPRING FRAMEWORK
스프링 컨트롤러에서 자바 스크립트 추가 하기
은호아빠
2023. 2. 20. 21:27
스프링 컨트롤러에서 자바 스크립트 추가 하기
PrintWriter 이걸 사용하면 되는데 요즘 UTF-8로 설정을 많이 해서 프로젝트 따라 자동으로 되는지 알았는데 설정을
해줘야 한다.
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
UTF-8로 해서 생성을 한다.
스크립트를 작성하면 페이지이동하면서 실행이 된다.
out.println("<script type='text/javascript'>");
out.println("alert('메인 홈으로 이동합니다.');");
out.println("window.location.href='"+request.getContextPath()+"/index';");
out.println("</script>");
out.flush();
return return_url_str;