이전글
2022.01.17 - [Coding story/go HTML,CSS,JSP] - 인터넷 서점 만들어보기(JSP/Java)-1.리스트출력
2022.01.17 - [Coding story/go HTML,CSS,JSP] - 인터넷 서점 만들어보기(JSP/Java)- 2.상세정보보기
# 신간추가 기능 넣기
#BookRepository.java
1
2
3
4
5
|
//새책 추가하기
public void addBook(Book book) {
listofBooks.add(book);
}
|
cs |
#addBook.jsp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/css/bootstrap.min.css"/>
<script src="/js/validationBook.js"></script>
<title>도서 등록</title>
<style>
h3{
text-align: center;
}
</style>
</head>
<body>
<!-- top 인클루드 -->
<jsp:include page="top.jsp"/>
<!-- top 인클루드 -->
<!-- content시작 -->
<div class="jumbotron">
<div class="container">
<h3 class="display-4">도서 등록</h3>
</div>
</div>
<div class="container">
<!-- addProduct_process.jsp : common-fileupload -->
<!-- addProduct_process2.jsp : cos.jar -->
<form name="newBook" action="processAddBook.jsp"
method="post" class="form-horizontal" enctype="multipart/form-data">
<div class="form-group row">
<label class="col-sm-2">도서코드</label>
<div class="col-sm-3">
<input type="text" name="isbn" id="isbn"
class="form-control" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">도서명</label>
<div class="col-sm-3">
<input type="text" name="bName" id="bName"
class="form-control" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">가격</label>
<div class="col-sm-3">
<input type="text" name="bPrice" id="bPrice"
class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">저자</label>
<div class="col-sm-3">
<input type="text" name="writer"
class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">출판사</label>
<div class="col-sm-3">
<input type="text" name="company"
class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">출판일</label>
<div class="col-sm-3">
<input type="text" name="bdate"
class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">총페이지 수</label>
<div class="col-sm-3">
<input type="text" name="totalpage"
class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">상세정보</label>
<div class="col-sm-6">
<textarea name="detail" rows="2" cols="50"
class="form-control"></textarea>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">분 류</label>
<div class="col-sm-3">
<input type="text" name="category"
class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">재고수</label>
<div class="col-sm-3">
<input type="text" name="stock" id="stock"
class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">상태</label>
<div class="col-sm-3">
<input type="radio" name="condition" id="condition1" value="신규도서"/>
<label for="condition1">신규도서</label>
<input type="radio" name="condition" id="condition2" value="중고도서"/>
<label for="condition2">중고도서</label>
<input type="radio" name="condition" id="condition3" value="E-BOOK"/>
<label for="condition3">E-BOOK</label>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">이미지</label>
<div class="col-sm-5">
<input type="file" name="BookImage" class="form-control" />
</div>
</div>
<div class="form-group row">
<div class="col-sm-offset-2 col-sm10">
<input type="button" class="btn btn-primary" onclick="CheckAddBook()" value="등록">
<input type="reset" class="btn btn-danger" value="초기화하기">
<a href="./login/logout.jsp" class="btn btn-warning">로그아웃</a>
</div>
</div>
</form>
</div>
<!-- bottom 인클루드 -->
<jsp:include page="bottom.jsp"/>
<!-- bottom 인클루드 -->
</body>
</html>
|
cs |
# 신간추가는 관리자만 가능하기에 관리자 로그인 걸어둠 (관리자 = admin)
#tomcat-user.xml (admin설정)
1
2
3
4
5
6
7
8
|
<!-- 사용자와 역할을 활성화 -->
<!-- web.xml에서 role-name에서 지정된다. -->
<role rolename="admin"/>
<role rolename="tomcat"/>
<user username="both" password="both1234" roles="tomcat,admin"/>
<user username="admin" password="admin1234" roles="admin"/>
<user username="tomcat" password="tomcat1234" roles="tomcat"/>
</tomcat-users>
|
cs |
#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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>BookMarket</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!--
error-code : 404(경로에 해당파일이 없다), 500(오타등 개발자실수)등의 응답 상태 코드
location : 오류 페이지의 URI(URL+기능)
-->
<error-page>
<error-code>404</error-code>
<location>/error/exceptionNoPage.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error/500.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/error/500.jsp</location>
</error-page>
<!-- 한글설정 필터추가 -->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 한글설정 END -->
<!-- security role1 시작 -->
<!-- <security-role> -->
<!-- <role-name>admin</role-name> -->
<!-- </security-role> -->
<!-- security 제약 사항 설정 -->
<security-constraint>
<web-resource-collection>
<web-resource-name>BookMarket</web-resource-name>
<!-- 접근을 제한할 요청 경로 -->
<url-pattern>/ch08/addBook.jsp</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<description>권한 관리자 아이디</description>
<!-- 권한이 부여된 role 이름 -->
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<!-- security 인증 설정 -->
<login-config>
<!-- BASIC 인증 처리 기법으로 설정 -->
<!-- <auth-method>BASIC</auth-method> -->
<!-- FORM 기반 인증 처리 기법으로 설정 -->
<!-- FORM 기반으로 인증할시 별도의 login창을 만들어야한다. -->
<auth-method>FORM</auth-method>
<form-login-config>
<!-- 인증 처리를 위한 로그인 페이지 설정 -->
<form-login-page>/ch08/login/login.jsp</form-login-page>
<!-- 인증 실패시 오류 페이지 설정 -->
<form-error-page>/ch08/login/login_failed.jsp</form-error-page>
</form-login-config>
</login-config>
<!-- security role1 끝 -->
</web-app>
|
cs |
#login.jsp (로그인페이지)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap.min.css"/>
<style>
.container{
text-align: center;
width: 1000px;
margin-top: 150px;
}
</style>
</head>
<body>
<div class="container">
<div class="card-header bg-primary text-white">
<h3 class="card-title">관리자 로그인이 필요합니다.</h3>
</div>
<!-- /.card-header -->
<div>
<c:if test="${param.error eq '1'}">
<div class="alert alert-warning">
아이디와 비밀번호를 확인해주세요
</div>
</c:if>
</div>
<!-- /.card-header end -->
<!-- form start -->
<form class="form-signin" method="get" action="j_security_check">
<div class="card-body">
<div class="form-group">
<label for="userid" class="sr-only">아이디</label>
<input type="text" class="form-control"
id="userid" placeholder="UserId" name="j_username" required autofocus>
</div>
<div class="form-group">
<label for="passwd" class="sr-only">비밀번호</label>
<input type="password" class="form-control"
id="passwd" placeholder="Password" name="j_password" required autofocus>
</div>
</div>
<!--form end -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">로그인</button>
<button type="reset" class="btn btn-warning">리셋</button>
<a href="<%=request.getContextPath()%>/ch08/books.jsp" class="btn btn-danger">돌아가기«</a>
</div>
</form>
</div>
</body>
</html>
|
cs |
# 관리자 로그아웃과 로그인 실패 창(logout.jsp / login_failed.jsp)
#logout.jsp (세션을 통해서 세션 값 삭제)
1
2
3
4
5
6
7
8
9
|
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
//세션 종료 = 로그아웃
session.invalidate();
response.sendRedirect("../books.jsp");
%>
|
cs |
#login_failed.jsp
1
2
3
4
5
6
7
8
9
10
11
|
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<title>로그인 실패</title>
</head>
<body>
<h2 style="text-align: center;"> 로그인에 실패하였습니다.</h2>
</body>
</html>
|
cs |
# 결과창
#login.jsp
#로그인 후 addbook.jsp
'Coding story > go Spring,JSP' 카테고리의 다른 글
스프링 시큐리티 (Spring Security) - 1 (0) | 2022.02.14 |
---|---|
#Spring(4) - JDBC연동 준비 (0) | 2022.02.03 |
#Spring(3) - 스프링의 예제로 본 동작 원리 (0) | 2022.01.29 |
#Spring(2) - 스프링MVC프로젝트의 구조, pom.xml (0) | 2022.01.27 |
#Spring(1) - STS 설치 및 MVC프로젝트 생성 (0) | 2022.01.27 |
최근댓글