728x90
3-4.
Redirect Login
LoginService.java
package ch03.ex04;
public class LoginService {
private String userId = "blueid";
private String userPw = "bluepw";
public boolean check(String userId, String userPw){
return userId.equals(this.userId) && userPw.equals(this.userPw);
}
}
redirectLoginIn.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">
<form action="redirectLoginProc.jsp" method="post">
<label>아이디: <input type="text" name="userId" /></label><br>
<label>암 호: <input type="password" name="userPw" /></label><br>
<input type="submit"/>
</form>
<%
String msgId = request.getParameter("msgId");
if(msgId != null && !msgId.equals("") && msgId.equals("-1")){
%>
<br>로그인 정보가 틀렸습니다.
<%
}
%>
redirectLoginProc.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="ch03.ex04.LoginService"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
LoginService checker = new LoginService();
String userId = request.getParameter("userId");
String userPw = request.getParameter("userPw");
if(userId != null && !userId.equals("")
&& userPw != null && !userPw.equals("")){
userId = userId.trim();
userPw = userPw.trim();
}
boolean isValid = checker.check(userId, userPw);
if(!isValid) response.sendRedirect("redirectLoginIn.jsp?msgId=-1");
else response.sendRedirect("redirectLoginOut.jsp"
+"?userId="+userId+"&userPw="+userPw);
%>
<!--
파라미터값을 보내주는 유형 2가지
1. form으로 보내주기
2. 쿼리 스트링(URL)을 이용해서 보내주기
-->
redirectLoginOut.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">
<%
String userId = request.getParameter("userId");
String userPw = request.getParameter("userPw");
%>
<h3>다음 정보로 로그인 성공했습니다.</h3>
아이디: <%= userId%><br>
암 호: <%= userPw%>
728x90
'WEB > JSP' 카테고리의 다른 글
[JSP] ch03-06. Scope (0) | 2017.11.14 |
---|---|
[JSP] ch03-05. Forward Login (0) | 2017.11.13 |
[JSP] ch03-02. Request (0) | 2017.11.13 |
[JSP] ch03-01. FOR문 (0) | 2017.11.13 |
[JSP] ch02-08. Include2 (0) | 2017.11.13 |
댓글