750
No
login_action.jsp
<%@page import="com.slipp.PasswordMismatchException"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="com.slipp.user.NotFoundUserException"%>
<%@page import="com.slipp.user.User"%>
<%@page import="com.slipp.db.Database"%>
<%@page import="javax.servlet.*" %>
<%
String userId=request.getParameter("userId");
String password=request.getParameter("password");
User user=Database.findByUserId(userId);
try{
User.login(userId, password);
session.setAttribute("userId", userId);
response.sendRedirect("/");
}catch(NotFoundUserException e){
request.setAttribute("errorMessage", "존재하지 않는 사용자 입니다. 다시 로그인하세요.");
RequestDispatcher rd=request.getRequestDispatcher("login.jsp");
rd.forward(request, response);
}catch(PasswordMismatchException e){
request.setAttribute("errorMessage", "비밀번호가 틀립니다. 다시 로그인하세요.");
RequestDispatcher rd=request.getRequestDispatcher("login.jsp");
rd.forward(request, response);
}
%>
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="/commons/_head.jspf" %>
<body>
<%@ include file="/commons/_top.jspf" %>
<div class="container">
<div class="row">
<div class="span12">
<section id="typography">
<div class="page-header">
<h1>로그인</h1>
</div>
<form class="form-horizontal" action="/login_action.jsp" method="post">
<c:if test="${not empty errorMessage}">
<div class="control-group">
<label class="error">${errorMessage}</label>
</div>
</c:if>
<div class="control-group">
<label class="control-label" for="userId">사용자 아이디</label>
<div class="controls">
<input type="text" name="userId" value="" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">비밀번호</label>
<div class="controls">
<input type="password" id="password" name="password" placeholder="">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">로그인</button>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
로그인
|
댓글 ( 4)
댓글 남기기