반응형
자바에서 자바스크립트 alert을 실행하는 방법
아래와 같은 스프링 예제 소스가 있습니다.
예제는 id와 pw를 받아서 해당 계정이 존재하는지 확인하는 소스이며,
계정정보가 존재하지 않는경우 자바스크립트를 통해 alert을 보여주며, 뒤로가리를 실행합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | @RequestMapping( "/loginAction" ) public String loginaction( @RequestParam(value= "userId" , required=true) String userId , @RequestParam(value= "password" ,required=true) String password , HttpServletRequest request , HttpServletResponse response ) throws Exception{ String url= "" ; MngVO mngVO = mngService.mngUserCheck(userId); if (mngVO != null){ url = "redirect:/" ; // "/admin/main/dashboard"; } else { response.setContentType( "text/html; charset=UTF-8" ); PrintWriter out = response.getWriter(); out.println( "<script>alert('로그인 정보를 확인해주세요.'); history.go(-1);</script>" ); out. flush (); } return url; } |
위의 소스중에서 아래의 부분이 자바에서 자바스크립트 alert을 실행하는 부분입니다.
1 2 3 4 | response.setContentType( "text/html; charset=UTF-8" ); PrintWriter out = response.getWriter(); out.println( "<script>alert('로그인 정보를 확인해주세요.'); history.go(-1);</script>" ); out. flush (); |
반응형
'SPRING > spring' 카테고리의 다른 글
The prefix "mvc" for element "mvc:interceptors" is not bound. (0) | 2017.01.03 |
---|---|
스프링 시큐리티 비밀번호 bcrypt 간단한 암호화 (2) | 2017.01.03 |
3. 이클립스 spring + mybatis + mysql 프로젝트 생성 (0) | 2016.12.04 |
2. 이클립스 spring + mybatis + mysql 프로젝트 생성 (0) | 2016.11.11 |
1. 이클립스 spring + mybatis + mysql 프로젝트 생성 (0) | 2016.11.11 |