
문제
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
0. web.xml
<init-param>
<param-name>id</param-name> <!-- 초기화 파라미터의 이름입니다. -->
<param-value>jsp</param-value> <!-- 초기화 파라미터의 값입니다. -->
</init-param>
<init-param>
<param-name>pass</param-name> <!-- 초기화 파라미터의 이름입니다. -->
<param-value>jsp</param-value> <!-- 초기화 파라미터의 값입니다. -->
</init-param>
1. 로그인 폼
http://localhost:8088/JspProject/ch5_implicit_object/_8.config/test/login.jsp
접속
2. 아이디와 비밀번호 입력
3. 전송(submit)후 이동 주소
http://localhost:8088/JspProject/loginTest
로그인에 성공하셨습니다.
아닌 경우에는
로그인에 실패하셨습니다.
출력합니다.
Colored by Color Scripter
|
|
loginSuccess.jsp파일을 실행해도 loginTest를 얻기 위해서 xml 파일을 제어한다.
문제를 풀기위해서 3번에 가장 집중해야 한다.
web.xml파일을 수정한다. 서블릿 이름은 임의로 지정해도 되지만 이름은 같아야 한다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<servlet>
<servlet-name>login</servlet-name>
<!--프로젝트명 이후의 경로를 적습니다. -->
<!--해당 서블릿에서 초기화 파라미터를 설정한 부분입니다.-->
<init-param>
<param-name>id</param-name> <!-- 초기화 파라미터의 이름입니다. -->
<param-value>jsp</param-value> <!-- 초기화 파라미터의 값입니다. -->
</init-param>
<init-param>
<param-name>pass</param-name> <!-- 초기화 파라미터의 이름입니다. -->
<param-value>jsp</param-value> <!-- 초기화 파라미터의 값입니다. -->
</init-param>
</servlet>
<servlet-mapping>
<!--url 패턴-->
<servlet-name>login</servlet-name>
<url-pattern>/loginTest</url-pattern>
</servlet-mapping>
Colored by Color Scripter
|
|
login 파일은 다음과 같다.
submit을 누르면 로그인테스트라는 url을 갖는 파일로 가야한다.
누르면 가는 것은 action이다. action의 경로를 원하는 url값으로 가지 위해서
<%=application.getContextPath()%>/loginTest를 가져온다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>로그인 입력</title>
</head>
<body>
<!-- application.getContextPath() / jspProject -->
<!-- action에 대한 주소 jsp/task00513/loginTest -->
<form action='<%=application.getContextPath()%>/loginTest' method="POST">
<h1>로그인</h1>
<hr>
<b>아이디</b>
<input type = "text" name = "id" placeholder="Enter id" required>
<b>비밀번호</b>
<input type = "text" name = "passwd" placeholder="Enter password" required>
<div class = "clearfix">
<button type = "submit" class = "submitbtn">Submit</button>
<button type = "reset" class = "cancelbtn">Cancel</button>
</div>
</form>
</body>
</html>
Colored by Color Scripter
|
|
loginSuccess파일은 다음과 같다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>로그인 성공</title>
<style>
@keyframes sway {
0% {color:blue;}
25% {color:green;}
50% {color:orange;}
75% {color:yellow;}
100% {color:red;}
}
.h{
animation:sway 2s infinite;
text-align:center;
}
</style>
</head>
<body>
<%
String id = config.getInitParameter("id");
String password = config.getInitParameter("pass");
String inputid = request.getParameter("id");
String inputpwd = request.getParameter("passwd");
if(id.equals(inputid) && password.equals(inputpwd)){
session.setAttribute("id", id);
%>
<h1 class ="h">로그인에 성공하셨습니다.</h1>
<%
}else{%>
<h1 class ="h">로그인에 실패하셨습니다.</h1>
<% } %>
</body>
</html>
Colored by Color Scripter
|
|
'IT > JSP' 카테고리의 다른 글
| Error page 관리 (0) | 2019.05.13 |
|---|---|
| Exception (0) | 2019.05.13 |
| Config vs application (0) | 2019.05.13 |
| config (0) | 2019.05.13 |
| jsp만 이용해서 로그인처리하기 (0) | 2019.05.13 |