공부/JAVA | JSP&Servlet | Spring

jsp/servlet button 눌렀을 때 창 띄우기 (비밀번호 맞는지 체크)

bumcrush 2019. 2. 23. 15:24
반응형

jsp/servlet button 눌렀을 때 창 띄우기 (비밀번호 맞는지 체크) _ open_win 띄우기

- boardVeiw.jsp 에서 게시글 수정을 눌렀을 때 비밀번호 입력하라는 작은 창 띄운 후 

- 비밀번호가 맞는지 체크 하는 코드


boardVeiw.jsp 

<script type="text/javascript" src="script/board.js"></script> 


<input type="button" value="게시글 수정"

onclick="open_win('BoardServlet?command=board_check_pass_form&num=${board.num}', 'update')">

***형광펜 url부분임



script/board.js

function open_win(url, name) {

window.open(url, name, "width=500, height=230");

}   //url로 가서 창만들어라


function passCheck() {

if (document.frm.pass.value.length == 0) {

alert("비밀번호를 입력하세요.");

return false;

}

return true;

}




boardCheckPass.jsp  (url 서블릿 걸쳐 최종으로 오면 여기임_ window.open으로 띄울 부분)

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

<link rel="stylesheet" href="css/shopping.css">

<script type="text/javascript" src="script/board.js"></script>

</head>

<body>

<div align="center">

<h1>비밀번호 확인</h1>

<form action="BoardServlet" name="frm" method="get">

<input type="hidden" name="command" value="board_check_pass">

<input type="hidden" name="num" value="${param.num}">

<table style="width: 80%">

<tr>

<th>비밀번호</th>

<td><input type="password" name="pass" size="20"></td>

</tr>

</table>

<br> <input type="submit" value=" 확 인 "

onclick="return passCheck()"> <br>

<br>${message}

</form>

</div>

</body>

</html> 



BoardCheckPassAction.java (board_check_pass 서블릿 걸쳐 오는 곳)

public class BoardCheckPassAction implements Action {

@Override

public void execute(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

String url = null;

String num = request.getParameter("num");

String pass = request.getParameter("pass");

BoardDAO bDao = BoardDAO.getInstance();

BoardVO bVo = bDao.selectOneBoardByNum(num);

if (bVo.getPass().equals(pass)) { // 성공

url = "/board/checkSuccess.jsp";

} else {// 실패

url = "/board/boardCheckPass.jsp";

request.setAttribute("message", "비밀번호가 틀렸습니다.");

}

RequestDispatcher dispatcher = request.getRequestDispatcher(url);

dispatcher.forward(request, response);

}


checkSuccess.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>

<script type="text/javascript">

if (window.name == "update") {

window.opener.parent.location.href = "BoardServlet?command=board_update_form&num=${param.num}";

} else if (window.name == 'delete') {

alert('삭제되었습니다.');

window.opener.parent.location.href = "BoardServlet?command=board_delete&num=${param.num}";

}

window.close();

</script>

</body>

</html> 



참고 코드 ;  https://github.com/sbomhoo/servlet_board

반응형
  • 현재글jsp/servlet button 눌렀을 때 창 띄우기 (비밀번호 맞는지 체크)