[JSP] ch03-05. Forward Login

2017. 11. 13. 15:09·WEB/JSP
728x90
반응형

3-5. Forward Login

LoginService.java

package ch03.ex05;

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);
    }
}

 

forwardLoginIn.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="forwardLoginProc.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>로그인 정보가 틀렸습니다.        
<%
    }
%>

 

forwardLoginProc.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="ch03.ex05.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");
    
    boolean isValid = false;
    if(userId != null && !userId.equals("")
            && userPw != null && !userPw.equals("")){
        userId = userId.trim();
        userPw = userPw.trim();
        isValid = checker.check(userId, userPw);
    }
    
    if(!isValid) response.sendRedirect("forwardLoginIn.jsp?msgId=-1");
    else{
        request.setAttribute("msg","로그인 성공");
%>
    <jsp:forward page="forwardLoginOut.jsp"/>
<%
    }
%>
 

forwardLoginOut.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><%= request.getAttribute("msg")%></h3>
아이디:<%=userId%><br>
암 호:<%=userPw%>
 

728x90
반응형

'WEB > JSP' 카테고리의 다른 글

[JSP] ch03-07. Include3  (0) 2017.11.14
[JSP] ch03-06. Scope  (0) 2017.11.14
[JSP] ch03-04. Redirect Login  (0) 2017.11.13
[JSP] ch03-02. Request  (0) 2017.11.13
[JSP] ch03-01. FOR문  (0) 2017.11.13
'WEB/JSP' 카테고리의 다른 글
  • [JSP] ch03-07. Include3
  • [JSP] ch03-06. Scope
  • [JSP] ch03-04. Redirect Login
  • [JSP] ch03-02. Request
밍글링글링
밍글링글링
mingling - 밍글링, 밍글밍글링. 코드와 어우러지다. IT/ 프로그래밍/소스
    반응형
    250x250
  • 밍글링글링
    mingling
    밍글링글링
  • 전체
    오늘
    어제
    • 밍글링글링 (463)
      • Flutter (2)
      • 일상생활 (8)
        • 리뷰 (1)
        • 생활정보 (4)
        • 맛집 (0)
        • 여행 (0)
        • 모든정보 (3)
      • JAVA (126)
        • 개념 (6)
        • 예제 (115)
        • Exception (2)
      • C (1)
        • C (1)
        • C++ (0)
        • C# (0)
      • JS (29)
        • JavaScript (18)
        • JQuery (5)
        • AJax (0)
        • NODE.JS (6)
        • Angular.JS 2.0 (0)
      • WEB (87)
        • HTML (6)
        • CSS (61)
        • JSP (20)
        • JSTL (0)
      • FrameWork (8)
        • Spring (8)
        • BootStrap (0)
        • MyBATIS (0)
        • JUnit (0)
      • 외부 라이브러리 (5)
      • 공유 소스 관리 (5)
        • Git (5)
        • SVN (0)
      • 빅데이터 프로그래밍 (37)
        • Python (37)
        • R Programming (0)
      • DB (7)
        • ORACLE (0)
        • MySql (6)
      • Development Tools (7)
        • StarUML (0)
        • eXERD (0)
        • Eclipse (4)
      • SKILL (6)
        • Migration (0)
        • Security (6)
      • MicroSoft (0)
        • Excel (0)
        • Word (0)
      • Android (0)
      • Server (21)
        • Ubuntu (5)
        • Linux (15)
      • IOS (0)
      • XML (0)
      • 미디어 (0)
      • 공지사항 (3)
      • NETWORK (1)
      • 게임 (4)
        • 피파 (1)
        • 리니지M (0)
        • 배틀그라운드 (1)
        • 듀랑고 (2)
      • 세상 이슈 (6)
      • 일렉트론 (0)
      • 대회 소식 (4)
      • 업무 (2)
      • Express, Vue (6)
      • docker (11)
      • svelte (3)
      • 블록체인 (1)
      • IT (66)
      • Rust (0)
  • 블로그 메뉴

    • 홈
    • 태그
    • 미디어로그
    • 위치로그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    티스토리 자동화
    자바 생성자
    gitlab 설치
    ubuntu
    프런트엔드
    jsp include
    브라우저 자동화
    vscode
    css float
    nginx
    Rust lang
    클론코딩
    vue 설치
    rust linux
    VS Code 팁
    svelte
    Extension Bisect
    docker
    제미나이
    nginx ssl 설정
    자바 클래스
    자바 for문
    css perspective
    오류
    nginx ssl 적용
    AI 반도체
    servlet class
    자바 exception
    java casting
    리눅스 설치
    React Compiler
    mysql db
    Node
    jsp parameter
    SSL 인증서
    ssl 인증서 발급
    러스트
    css tb
    css table
    자바 배열
    에디터 팁
    proxy pass
    Java Array
    spring java
    자바 객체 지향
    AI 코딩 에이전트
    API 설계
    vue cli
    lang rust
    css transition
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
밍글링글링
[JSP] ch03-05. Forward Login
상단으로

티스토리툴바