728x90

 

기존 배우던 코드를 쭉 편하게 따라치면서 구조 분석하고 대강 틀만보고 안보고 치면서 세부코드 치는 연습

그리고 코딩 자체가 많이 익숙해지고 에너지 소모가 덜 되서 자연스러울 수 있게 하기 위한 목적으로 

머리 안돌아갈 때마다 쭉 따라치면서 가볍게 많이!!

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<link rel="stylesheet" type="text/css" href="member-style.css">

<style>
    span.guide{display: none; font-size:12px; top:12px; right:10px;}
    span.ok{color:green;}
    span.error{color:red;}
</style>

</head>
<body>

    <jsp:include page="../common/menubar.jsp"/>
    <h1 align="center">회원가입</h1>

    <div class="centerText">
        <form action="minsert.me" method="post" id="joinForm">
            <table>
                <tr>
                    <th>* 아이디</th>
                    <td>
                        <input type="text" name="id" id="userId">
                        <span class="guide ok">사용 가능한 아이디</span>
                        <span class="guide error">사용 불가능 아이디</span>
                        <input type="hidden" id="idDuplicateCheck" value="0"/>
                    </td>
                </tr>
                <tr>
                    <th>* 이름</th>
                    <td><input type="text" name="name"></td>
                </tr>
                <tr>
                    <th>* 비밀번호확인</th>
                    <td><input type="password" name="pwd"></td>
                </tr>    
                <tr>
                    <th>닉네임</th>
                    <td><input type="text" name="nickName"></td>
                </tr>
                <tr>
                    <th>성별</th>
                    <td>
                        <input type="radio" name="gender" value="M">남
                        <input type="radio" name="gender" value="F">여
                    </td>
                </tr>
                <tr>
                    <th>나이</th>
                    <td><input type="number" name="age" min="20" max="100"></td>
                </tr>
                <tr>
                    <th>이메일</th>
                    <td><input type="email" name="email"></td>
                </tr>
                <tr>
                    <th>전화번호</th>
                    <td><input type="tel" name="phone"></td>
                </tr>
                <tr>
                    <th>우편번호</th>
                    <td>
                        <input type="text" name="post" class="postcodify_postcode5" value="" size="6">
                        <button type="button" id="postcodify_search_button">검색</button>
                    </td>
                </tr>
                <tr>
                    <th>도로명 주소</th>
                    <td><input type="text" name="address1" class="postcodify_address" value=""></td>
                </tr>
                <tr>
                    <th>상세 주소</th>
                    <td><input type="text" name="address2" class="postcodify_extra_info" value=""></td>
                </tr>

                <!-- jQuery & Postcodify 로딩 -->
                <script src="//d1p7wdleee1q2z.cloudfront.net/post/search.min.js"></script>
                <script>
                    // 검색 단추가 열리면 팝업 레이어가 열리도록 설정
                    $(function(){
                        $("#postcodify_search_button").postcodifyPopUp();
                    });
                </script>
                
                <tr>
                    <td>
                        <button onclik="return validate();">가입하기</button>
                        <input type="reset" value="취소하기">
                        <button type="button" onclick="location.href='home.do'">시작 페이지로</button>
                    </td>
                </tr>

            </table>        
        </form>
    </div>

    <script>
        ${'#userId'}.on('keyup',function(){
            var userId = $(this).val().trim(); // trim() : 앞뒤 공백제거

            if(userId.length < 4){
                $('.guide').hide();
                $('#idDuplicateCheck').val(0);

                return;
            }

            $.ajax({
                url: 'dupId.me',
                date: {id:userId},
                success: function(date){
                    console.log(date);

                    if(data == 1){ /* 이 데이터가 원래는 str타입으로 넘어가고 있으나 js에서 알아서 형변환 */
                        $('.guide.error').show();
                        $('.guide.ok').hide();
                        $('#idDuplicateCheck').val(0); // 에러라 유효성 필요없으니 0보냄
                    }else{
                        $('.guide.error').hide();
                        $('guide.ok').show();
                        $('#idDuplicateCheck').val(1);  // 에러없으니 유효성 검사 필요해서 1보냄
                    }
                },
                error: function(data){
                    console.log(data);
                }
            });
        });
    
    function validate(){
        if($('#idDuplicateCheck').val() == 0){
            alert('사용 가능한 아이디를 입력해주세요');
            $('#userId').focus();
            return false();
        } else{
            $('#joinForm').submit();
        }
    }


    </script>




</body>
</html>

 

 

728x90
반응형
728x90

 

<목표>

따라치되 최대한 안보고 코딩하기

코딩 익숙해지기

구조 분석

세부코드 안보고 쓸 수 있게 되기

 

반복이 살 길이다!!!!!!!

 

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<script src="${ contextPath }/resources/js/jquery-3.6.0.min.js"></script> 

<style>
	.nav{margin-left:auto; margin-right:auto; text-align:center;}
	.menu{
		display:inline-block; background:#e4fc41; text-align:center;
		line-height:50px; width:150px; height:50px; border-radius:20px;
		margin-left:5%; margin-right:5%;
	}
	.menu:hover{background:#b0c903; font-weight:bolder; cursor:pointer;}
	a:link{color:black; text-decoration:none;}
	a:visited{color:black; text-decoration:none;}
</style>

</head>
<body>

	<c:set var="contextPath" value="${ pageContext.servletContext.contextPath }" scope="application"/>
	
	<h1 align="center">first page & Spring</h1>
	<br>
	
	
	<div class="loginArea" align="right">
		<c:if test="${ empty sessionScope.loginUser }">	<!-- user가 로그인 안했으면 로그인하게 id,pw 보여주는 창 보여줌-->
			<form action="login.me" method="post">
				<table id="loginTable" style="text-align:center;">
					<tr>
						<td>아이디</td>
						<td><input type="text" name="id"></td>
						<td rowspan="2">
							<button id="loginBtn">로그인</button>
						</td>
					</tr>
					<tr>
						<td>비밀번호</td>
						<td><input type="password" name="pwd"></td>
					</tr>
					<tr>
						<td colspan="3">
							<button type="button" onclick="location.href='enrollView.me'">회원가입</button>
							<button type="button">아이디/비밀번호 찾기</button>"
						</td>					
					</tr>
				</table>
			</form>
		</c:if>
	
		<c:if test="${ empty sessionScope.loginUser }"> <!-- user가 로그인했으면 정보 변경, 로그아웃 등 보여줌 -->
			<h3 align="right"> <!-- h3태그 안에 c core와 button태그를 넣은게 신기 -->
				<c:out value="${ loginUser.name }님 환영합니다."/>
				<br>
				<c:url var="myinfo" value="myinfo.me"/>
				<c:url var="logout" value="logout.me"/>
				<button onclick="location.href='${myinfo}'">정보보기</button>
				<button onclick="location.href='${logout}'"	>로그아웃</button>
							<!-- c:url에서 var변수로 지정한 것을 버튼클릭하면 이동하게만듬 -->
			</h3>		
		</c:if>
	</div>
	

<!-- 위처럼 c:url을 통해서 지정할 수도 있지만 지금까지 해왔던 것처럼 바로 href에 url을 넣어도 상관없음 -->
	<div class="menubar">
		<div class="nav">
			<div class="menu"><a href="home.do">Home</a></div>
			<div class="menu"><a href="blist.bo">게시판</a></div>		
		</div>
	</div>


</body>
</html>

 

 

728x90
반응형
728x90

 

비밀번호 수정 폼

클론 코딩 & 구조 파악

손코딩으로 하나씩 익히기

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> prac</title>

<link rel="stylesheet" type="text/css" href="${pageContext.servletContext.contextPath }/resources/css/member-style.css"> 

</head>
<body>

	<c:import url="../common/menubar.jsp"/>

	<h1 align="center">비밀번호 수정</h1>
	
	<div class="centerText">
		<form action="mPwdUpdate" method="post">
			<table>
				<tr>
					<th>현재 비밀번호</th>
					<td><input type="password" name="pwd"></td>
				</tr>
				<tr>
					<th>새 비밀번호</th>
					<td><input type="password" name="newPwd1"></td>
				</tr>
				<tr>
					<th>새 비밀번호 확인</th>
					<td><input type="password" name="newPwd2"></td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						<input type="submit" value="수정하기">
						<button type="button" onclick="location.href='home.do'">시작화면으로</button>
					</td>
				</tr>
				
			</table>
		</form>	
	</div>

</body>
</html>
728x90
반응형
728x90

 

관리자 페이지에서 공지사항 작성할 수 있게 쓰기 페이지 제작

인풋태그로 짧은 글 받고

텍스트 애어리어로 내용 부분 받아서 컨트롤러로 전달

쓰기 폼하나 새로 만들고 이를 작성완료하면 db쪽과 왔다갔다 하도록 구성

 

HTML

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>


<link rel="stylesheet" type="text/css" href="${ pageContext.servletContext.contextPath }/resources/css/admin/adminNoticeWriteView.css">



</head>
<body>

	<c:import url="adminMenubar.jsp" />



    <div class="title">
        <h2>공지사항</h2>   
    </div>    
    
	<form id="form" name="form" method="post">
	    <table class="tableWhole">
	            <thead>
	                <tr>
	                    <th>제목</th>
	                        <td style="width: 1050px;">
	                        	<input type="text" placeholder="제목을 입력하세요">
	                        </td>
	                </tr>
	                <tr>
	                    <th>작성자</th>
	                    <td>${board.adminId}</td>
	                </tr>
	                <tr>
	                    <th>작성일</th>
	                    <td>${board.boardCreateDate}</td>
	                    <th>조회수</th>
	                    <td style="width:100px" align="center">
	                    	${board.boardCount}
	                    </td>
	                </tr>
	            </thead>
	    </table>
    

	    <div class="content">
	        <textarea class="textarea_field" placeholder="   내용을 입력해주세요."></textarea>
	    </div>
			<input type="hidden" id="boardId" name="boardId" value="${board.boardId }" > <!-- qnaNo를 컨트롤러로 보내서 어느 게시물이 수정되는지 알려 줘야함  -->
	    <div class="listButton">
	    	<c:url var="blist" value="adminNoticeList.ad">
				<c:param name="page" value="${ page }"/>
			</c:url>
	        <button type="submit" onclick="javascript:form.action='adminNoticeWriteForm.ad'">작성 완료</button> 
	        <button type="submit" onclick="javascript:form.action='adminNoticeList.ad'">목 록</button> 
	    </div>
	 </form> 
    




<!-- ############ PAGE END 끝~ -->

<!-- / -->

<!-- theme switcher -->

<!-- ############ LAYOUT END-->

<!-- build:js scripts/app.html.js -->
<!-- jQuery -->
<script src="${ pageContext.servletContext.contextPath }/resources/libs/jquery/jquery/dist/jquery.js"></script>
<!-- Bootstrap -->
<script src="${ pageContext.servletContext.contextPath }/resources/libs/jquery/tether/dist/js/tether.min.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/libs/jquery/bootstrap/dist/js/bootstrap.js"></script>
<!-- core -->
<script src="${ pageContext.servletContext.contextPath }/resources/libs/jquery/underscore/underscore-min.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/libs/jquery/jQuery-Storage-API/jquery.storageapi.min.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/libs/jquery/PACE/pace.min.js"></script>

<script src="${ pageContext.servletContext.contextPath }/resources/scripts/config.lazyload.js"></script>

<script src="${ pageContext.servletContext.contextPath }/resources/scripts/palette.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/scripts/ui-load.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/scripts/ui-jp.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/scripts/ui-include.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/scripts/ui-device.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/scripts/ui-form.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/scripts/ui-nav.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/scripts/ui-screenfull.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/scripts/ui-scroll-to.js"></script>
<script src="${ pageContext.servletContext.contextPath }/resources/scripts/ui-toggle-class.js"></script>

<script src="${ pageContext.servletContext.contextPath }/resources/scripts/app.js"></script>

<!-- ajax -->
<%-- 	<script src="${ pageContext.servletContext.contextPath }/resources/libs/jquery/jquery-pjax/jquery.pjax.js"></script> --%>
<script src="${ pageContext.servletContext.contextPath }/resources/scripts/ajax.js"></script>
<!-- endbuild -->
    


</body>
</html>

 

CSS




th{
    width: 130px;
    background-color: #f7f5f8;
    font-weight: 600;
    line-height: 200%;
}

input{
	border:none;
}

.title{
    width: 890px;
    text-align: center;
    margin: 0 auto;
}
.title > p{
    color:rgb(149, 146, 146);
    margin-bottom: 3%;
}
thead{
    border-bottom: rgb(149, 146, 146);
}

.tableWhole{
    width:100%;
    max-width: 890px;
    border-top : 2px solid black;  
    border-bottom: 1px solid lightgray;
    line-height: 180%;
    margin: 0 auto;
}
.tableWhole > thead > tr > td{
	padding-left:10px;	
	padding-top:5px;
	padding-bottom:5px;
	
}
thead > tr{
    border-bottom : 1px solid rgb(149, 146, 146);  
}
.tableTop td{
    width:450px;
}

    
.content{
    width:890px;
    margin: 0 auto;
    word-break: break-all;
}
.content > p{
    padding: 2%;
    padding-bottom: 5%;
    border-bottom: 1px solid  lightgray;
}

.listButton{
    width:890px;
    text-align: right;
    margin:2% auto;
    padding-right: 3%;
    
}
.listButton > button:hover{
    background-color:#f7b7b5;
    color:#fff;
    border:1px solid #FE8F8F;
    
}
.listButton > button{
    width:100px;
    height:35px;
    background-color: #FE8F8F;
    border: 1px solid #FF5C58;
    color:#fff;
}

/**************************/

.content{
    text-align: center;
}
.content textarea{
    width:890px;
    min-height: 150px;
    padding:1% 0;
    margin: 0 auto;
    resize: none;
    border:none;
    border-bottom: 1px solid lightgray;
}

 

 

728x90
반응형
728x90

 

 

 

form태그 안에 여러개의 버튼과 submit이 필요한데

삭제할 때는 정말 지울껀지 확인 메세지까지 던져줘야해서

어떻게 할지 막혀있던 상태

 

삭제 버튼만 type="button"으로 바꿔주고 삭제 메세지가 뜰 수 있게 js함수로 만들어서

밖으로 빼두었다

 

<form id="form" name="form" method="post">
	<div class="listButton">
    	<c:url var="blist" value="adminNoticeList.ad">
			<c:param name="page" value="${ page }"/>
		</c:url>
        <button type="submit" onclick="javascript:form.action='adminNoticeUpdateForm.ad'">수정</button> 
        <button type="button" onclick="ConfirmDelete()">삭제</button> 
        <button type="submit" onclick="javascript:form.action='adminNoticeList.ad'">목록</button> 
 
    </div>
 </form>

 

정말 지울껀지 confirm()을 이용해서 확인절차 거치고

어느 게시판을 삭제할지 해당 게시판 번호를 알아야해서 boardId를 컨트롤러로 보내주고

form태그에 id속성을 줘서 밖에서도 form를 쓸 수 있게 getElementById를 사용해서 submit 시키고

location.href로 url과 동시에 boardId도 같이 보내준다

 (참고로 location.href는 get방식)

<script>
	function ConfirmDelete(){
		var ask = confirm("정말로 삭제하시겠습니까?");
		if(ask){
			var boardId = $('#boardId').val();
			document.getElementById('form').submit();
			location.href='adminNoticeDelete.ad?boardId='+boardId;
		}
	};
</script>
728x90
반응형
728x90

 

분명 수정 후 게시판 전체조회로 가게끔 url 설정을 해두었는데

수정하고 나서 print찍히는거보면 상세보기로 가게 되어있는 것이다.

url 지정도 제대로 했는데 왜 뜬금없이 상세보기의 print가 찍혔나 봤더니

 

form태그 하나 안에 버튼이 여러개인데 이것들이 충돌되고 이중에서 상세보기 url이 

남아있는 구조가 되어버려서 뜬금없이 일로 튀는 것처럼 보이게된 것

 

<form id="form" name="form" method="post">
    <button type="submit" onclick="javascript:form.action='adminNoticeUpdateForm.ad'">수정</button> 
    <button type="button" onclick="ConfirmDelete()">삭제</button> 
    <button type="submit" onclick="javascript:form.action='adminNoticeList.ad'">목록</button>
 </form>

위에 처럼 버튼에 각각 타입 지정해주고 온클릭에 자바스크립트 코드를 넣어서 해결함

이렇게 하면 하나의 폼태그에 버튼 태그 각각에 액션 속성을 주어 따로따로 url 갈 수 있게 된다

728x90
반응형
728x90

 

세션 영역에 있는 관리자 로그인 정보 중에 id만 가져와서

admin 테이블로 casting하고 다시 보드 테이블에 넣어주어 이를 공지사항 쓰기할 때

고정적으로 작성자에 보여주는걸로 코드 수정 및 기능 추가

 

	@RequestMapping("adminNoticeWriteView.ad")
	public String adminNoticeWriteView() {
		return "adminNoticeWriteView";
	}

 

	@RequestMapping("adminNoticeWriteView.ad")
	public String adminNoticeWriteView(@ModelAttribute Board b, Model model, HttpSession session) {
		
		String adId = ((Admin)session.getAttribute("adminUser")).getId();
		b.setAdminId(adId);
		model.addAttribute("b",b);
		
		return "adminNoticeWriteView";
	}

 

728x90
반응형
728x90

 

손코딩 

디테일 익히기

구조파악!

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> prac </title>

<link rel="stylesheet" href="${pageContext.servletContext.contextPath }/resources/css/member-style.css">

</head>
<body>

	<c:import url="../common/menubar.jsp"/>
	
	<h1 align="center">비밀번호 수정</h1>

	<div class="centerText">
		<form action="mPwdUpdate.me" method="post">
			<table>
				<tr>
					<th>현재 비밀번호</th>
					<td><input type="password" name="pwd"></td>
				</tr>
				<tr>
					<th>새 비밀번호</th>
					<td><input type="password" name="newPwd1"></td>
				</tr>
				<tr>
					<th>새 비밀번호 확인</th>
					<td><input type="password" name="newPwd2"></td>
				</tr>
				
				<tr>
					<td colspan="2" align="center">
						<input type="submit" value="수정하기">
						<button type="button" onclick="location.href='home.do'">시작 목록으로</button>
					</td>
				</tr>
				
			</table>		
		</form>
	</div>


</body>
</html>
728x90
반응형
728x90

 

시스템에서 에러 발생했을 때 에러메세지 처리하는 페이지 작성

에러메시지 처리

<%@ page language="java" contetnType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>prac</title>

</head>
<body>

	<div id="error=container" style="text-alignLcenter;">
	
		<h1>Error</h1>
		
		<h2 style="color red;">${ msg }</h2>
		<h2 style="color blue;">${requestScope['javax.servlet.error.message'] }</h2>
		
		<a href="home.do">시작 페이지로</a>
	</div>


</body>
</html>
728x90
반응형
728x90

 

비밀번호 수정폼

손코딩!

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> prac</title>

<link rel="stylesheet" type="text/css" href="${pageContext.servletContext.contextPath }/resources/css/member-style.css"> 

</head>
<body>

	<c:import url="../common/menubar.jsp"/>

	<h1 align="center">비밀번호 수정</h1>
	
	<div class="centerText">
		<form action="mPwdUpdate" method="post">
			<table>
				<tr>
					<th>현재 비밀번호</th>
					<td><input type="password" name="pwd"></td>
				</tr>
				<tr>
					<th>새 비밀번호</th>
					<td><input type="password" name="newPwd1"></td>
				</tr>
				<tr>
					<th>새 비밀번호 확인</th>
					<td><input type="password" name="newPwd2"></td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						<input type="submit" value="수정하기">
						<button type="button" onclick="location.href='home.do'">시작화면으로</button>
					</td>
				</tr>
				
			</table>
		</form>	
	</div>

</body>
</html>
728x90
반응형

+ Recent posts