본문 바로가기
SPRING

230228_Tiles

by 경 훈 2023. 2. 28.

타일즈 tiles : 화면 위치 프레임워크

= (시멘틱구조에서 top.jsp...footer.jsp...body...side.jsp)
1.pom.xml 파일에 4개 라이브러리 설치

tiles-core   ,   tiles-sevlet   ,   tiles-jsp   ,    tiles-template

2. servlet-context.xml 파일에 추가하기 위해

    servlet-context.xml 일부수정

3. resource 폴더안에 tiles 폴더생성

    여기에 새로운 jsp 파일을 등록후 실행

4. layout.jsp에서 css 내용

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<header>
<h1 align="center">
OO 고등학교 성적처리 프로그램
</h1>
</header>
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="/kim7_001/">HOME</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">
        <li class="active">
        </li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">성적관리<span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="in">입력</a></li>
          <li><a href="out">출력</a></li>
          <li><a href="search">검색</a></li>
          <li><a href="mapgo">지도보기</a></li>
          </ul>
        </li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">인사관리<span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="input.jsp">입력</a></li>
          <li><a href="out.do">출력</a></li>
          <li><a href="modify1.jsp">수정</a></li>
          <li><a href="delete1.jsp">삭제</a></li>
          <li><a href="search.jsp">검색</a></li>
          </ul>
        </li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">자재관리<span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="input.jsp">입력</a></li>
          <li><a href="out.do">출력</a></li>
          <li><a href="modify1.jsp">수정</a></li>
          <li><a href="delete1.jsp">삭제</a></li>
          <li><a href="search.jsp">검색</a></li>
          </ul>
        </li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">로그인관리 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="mem">회원가입</a></li>
            <li><a href="login">로그인</a></li>
          	<li><a href="logout">로그아웃</a></li>
          </ul>
        </li>
      </ul>
		<ul class="nav navbar-nav navbar-right">
		<c:choose>
			<c:when test="${login == true && listb != null}">		
				<c:forEach items="${listb}" var="listb">
				<a href="logout"><span class="glyphicon glyphicon-log-in"></span>환영합니다!! ${listb.id}님</a>
				</c:forEach>
				<a href="logout"><span class="glyphicon glyphicon-log-in"></span>로그아웃</a>
			</c:when>
			<c:otherwise>
	      		<li><a href="mem"><span class="glyphicon glyphicon-user"></span>회원가입</a></li>
	      		<li><a href="login"><span class="glyphicon glyphicon-log-in"></span>로그인</a></li>
	    	</c:otherwise>
    	</c:choose>
    	</ul>
	</div>
	</div>
</nav>
</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>
</head>
<body>
	<h3 align="center">
	성적입력
	</h3>
	<form action="scoresave" method="post">
		<table border="1" align="center">
			<tr>
				<th>반</th>
				<td><input type="text" name="ban"></td>
			</tr>
			<tr>
				<th>번호</th>
				<td><input type="text" name="num"></td>
			</tr>
			<tr>
				<th>이름</th>
				<td><input type="text" name="name"></td>
			</tr>
			<tr>
				<th>국어</th>
				<td><input type="text" name="kor"></td>
			</tr>
			<tr>
				<th>영어</th>
				<td><input type="text" name="eng"></td>
			</tr>
			<tr>
				<th>수학</th>
				<td><input type="text" name="mat"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="전송">
					<input type="reset" value="리셋">
				</td>
			</tr>
		</table>
	</form>
</body>
</html>

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<c:choose>
		<c:when test="${login == true && listb != null}">
		<h3 align="center">
		성적출력
		</h3>
		<table border="1" align="center" width="800px">
			<tr>
				<th>반</th><th>번호</th><th>이름</th>
				<th>국어</th><th>영어</th><th>수학</th>
				<th>총점</th><th>비고</th>
			</tr>
			<c:forEach items="${list}" var="list">
			<tr>
				<td>${list.ban}</td><td>${list.num}</td><td>${list.name}</td>
				<td>${list.kor}</td><td>${list.eng}</td><td>${list.mat}</td>
				<td>${list.tot}</td>
				<td>
					<a href="delete?name=${list.name}">&#10060;</a>
					<a href="modify?name=${list.name}">&#9989;</a>
				</td>
			</tr>
			</c:forEach>
		</table>
		</c:when>
		<c:otherwise>
			<script type="text/javascript">
				window.onload=function() {
					alert("로그인 후에 사용해주세요!")
				}
			</script>
		</c:otherwise>
	</c:choose>
</body>
</html>

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h3 align="center">
	성적수정
	</h3>
	<form action="scoresave" method="post">
		<table border="1" align="center">
			<c:forEach items="${list}" var="list">
			<tr>
				<th>반</th>
				<td><input type="text" name="ban" value="${list.ban}"></td>
			</tr>
			<tr>
				<th>번호</th>
				<td><input type="text" name="num" value="${list.num}"></td>
			</tr>
			<tr>
				<th>이름</th>
				<td><input type="text" name="name" value="${list.name}" readonly></td>
			</tr>
			<tr>
				<th>국어</th>
				<td><input type="text" name="kor" value="${list.kor}"></td>
			</tr>
			<tr>
				<th>영어</th>
				<td><input type="text" name="eng" value="${list.eng}"></td>
			</tr>
			<tr>
				<th>수학</th>
				<td><input type="text" name="mat" value="${list.mat}"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="수정">
					<input type="reset" value="리셋">
				</td>
			</tr>
			</c:forEach>
		</table>
	</form>
</body>
</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>
</head>
<body>
	<h3 align="center">
	성적 검색
	</h3>
	<form action="search2">
		<table border="1" align="center">
			<tr>
				<th>분류</th>
				<th>데이터</th>
			</tr>
			<tr>
				<td>
					<select name="item">
						<option value="name">이름</option>
						<option value="ban">반</option>
					</select>
				</td>
				<td><input type="text" name="value"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="전송">
					<input type="reset" value="초기화">
				</td>
			</tr>
		</table>
	</form>
</body>
</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>
</head>
<body>
	<h3 align="center">
	회원가입폼
	</h3>
	<form action="savemember" method="post">
		<table border="1" align="center">
			<tr>
				<th>아이디</th>
				<td><input type="text" name="id"></td>
			</tr>
			<tr>
				<th>비밀번호</th>
				<td><input type="password" name="pw"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="전송">
					<input type="reset" value="리셋">
				</td>
			</tr>
		</table>
	</form>
</body>
</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>
</head>
<body>
	<h3 align="center">
	로그인
	</h3>
	<form action="logincheck">
		<table border="1" align="center">
			<tr>
				<th>아이디</th>
				<td><input type="text" name ="id"></td>
			</tr>
			<tr>
				<th>비밀번호</th>
				<td><input type="password" name ="pw"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="로그인">
					<a href="mem"><input type="button" value="회원가입"></a>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>

 


package com.ezen.kim7_001;

public class ScoreDTO {
	int ban,num;
	String name;
	int kor,eng,mat,tot;
	public ScoreDTO() {
	}
	public ScoreDTO(int ban, int num, String name, int kor, int eng, int mat, int tot) {
		super();
		this.ban = ban;
		this.num = num;
		this.name = name;
		this.kor = kor;
		this.eng = eng;
		this.mat = mat;
		this.tot = tot;
	}
	public int getBan() {
		return ban;
	}
	public void setBan(int ban) {
		this.ban = ban;
	}
	public int getNum() {
		return num;
	}
	public void setNum(int num) {
		this.num = num;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getKor() {
		return kor;
	}
	public void setKor(int kor) {
		this.kor = kor;
	}
	public int getEng() {
		return eng;
	}
	public void setEng(int eng) {
		this.eng = eng;
	}
	public int getMat() {
		return mat;
	}
	public void setMat(int mat) {
		this.mat = mat;
	}
	public int getTot() {
		return tot;
	}
	public void setTot(int tot) {
		this.tot = tot;
	}
}

 

package com.ezen.kim7_001;

public class MemberDTO {
	String id,pw;
	public MemberDTO() {
	}
	public MemberDTO(String id, String pw) {
		super();
		this.id = id;
		this.pw = pw;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getPw() {
		return pw;
	}
	public void setPw(String pw) {
		this.pw = pw;
	}
}

 

package com.ezen.kim7_001;

import java.util.ArrayList;

public interface Service {
	public void insert(int ban,int num,String name,int kor,int eng,int mat,int tot);
	public ArrayList<ScoreDTO> out();
	public void delete(String dname);
	public ArrayList<ScoreDTO> modify(String mname);
	public ArrayList<ScoreDTO> searchname(String value);
	public ArrayList<ScoreDTO> searchban(String value);
	public void membersave(String id,String pw);
	public ArrayList<MemberDTO> logincheck(String id,String pw);
}

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "https://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.ezen.kim7_001.Service">
	<insert id="insert">
		insert into score228 values (#{param1},#{param2},#{param3},#{param4},#{param5},#{param6},#{param7})
	</insert>
	<select id="out" resultType="com.ezen.kim7_001.ScoreDTO">
		select * from score228 order by ban,num asc
	</select>
	<delete id="delete">
		delete from score228 where name=#{param1}
	</delete>
	<select id="modify" resultType="com.ezen.kim7_001.ScoreDTO">
		select * from score228 where name=#{param1}
	</select>
	<select id="searchname" resultType="com.ezen.kim7_001.ScoreDTO">
		select * from score228 where name like '%'||#{param1}||'%'
	</select>
	<select id="searchban" resultType="com.ezen.kim7_001.ScoreDTO">
		select * from score228 where ban like '%'||#{param1}||'%'
	</select>
	<insert id="membersave">
		insert into db02281 values (#{param1},#{param2})
	</insert>
	<select id="logincheck" resultType="com.ezen.kim7_001.MemberDTO">
		select * from db02281 where id=#{param1} and pw=#{param2}
	</select>
</mapper>

 

package com.ezen.kim7_001;


import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {
	@Autowired
	SqlSession sqlsession;
	@RequestMapping(value="/")
	public String ko1() {
		return "main";
	}
	@RequestMapping(value="/in")
	public String ko2() {
		return "scoreinput";
	}
	@RequestMapping(value="/scoresave")
	public String ko3(HttpServletRequest request) {
		int ban = Integer.parseInt(request.getParameter("ban"));
		int num = Integer.parseInt(request.getParameter("num"));
		String name = request.getParameter("name");
		int kor = Integer.parseInt(request.getParameter("kor"));
		int eng = Integer.parseInt(request.getParameter("eng"));
		int mat = Integer.parseInt(request.getParameter("mat"));
		int tot = kor+eng+mat;
		Service ss = sqlsession.getMapper(Service.class);
		ss.insert(ban,num,name,kor,eng,mat,tot);
		return "redirect:in";
	}
	@RequestMapping(value="/out")
	public String ko4(Model mo) {
		Service ss = sqlsession.getMapper(Service.class);
		ArrayList<ScoreDTO> list = ss.out();
		mo.addAttribute("list", list);
		return "output";
	}
	@RequestMapping(value="/delete")
	public String ko5(HttpServletRequest request) {
		String dname = request.getParameter("name");
		Service ss = sqlsession.getMapper(Service.class);
		ss.delete(dname);
		return "redirect:out";
	}
	@RequestMapping(value="/modify")
	public String ko6(HttpServletRequest request,Model mo) {
		String mname = request.getParameter("name");
		Service ss = sqlsession.getMapper(Service.class);
		ArrayList<ScoreDTO> list = ss.modify(mname);
		mo.addAttribute("list", list);
		return "modifyform";
	}
	@RequestMapping(value="/search")
	public String ko7() {
		return "searchform";
	}
	@RequestMapping(value="/search2")
	public String ko8(HttpServletRequest request,Model mo) {
		String item = request.getParameter("item");
		String value = request.getParameter("value");
		Service ss = sqlsession.getMapper(Service.class);
		ArrayList<ScoreDTO> list = null;
		if(item.equals("name")) {
			list = ss.searchname(value);
		}
		else {
			list = ss.searchban(value);
		}
		mo.addAttribute("list", list);
		return "output";
	}
	@RequestMapping(value="/mapgo")
	public String ko9() {
		return "map";
	}
	@RequestMapping(value="/mem")
	public String ko10() {
		return "member";
	}
	@RequestMapping(value="/savemember")
	public String ko11(HttpServletRequest request) {
		String id = request.getParameter("id");
		String pw = request.getParameter("pw");
		Service ss = sqlsession.getMapper(Service.class);
		ss.membersave(id, pw);
		return "redirect:mem";
	}
	@RequestMapping(value="/login")
	public String ko12() {
		return "login";
	}
	@RequestMapping(value="/logincheck")
	public String ko13(HttpServletRequest request) {
		String id = request.getParameter("id");
		String pw = request.getParameter("pw");
		Service ss = sqlsession.getMapper(Service.class);
		ArrayList<MemberDTO> listb = ss.logincheck(id, pw);
		HttpSession hs = request.getSession();
		if(listb.size()>0) {
			hs.setAttribute("listb", listb);
			hs.setAttribute("login", true);
			hs.setMaxInactiveInterval(60);
		}
		else {
			hs.setAttribute("login", false);
			return "login";
		}
		return "main";
	}
	@RequestMapping(value="/logout")
	public String ko14(HttpServletRequest request) {
		Service ss = sqlsession.getMapper(Service.class);
		HttpSession hs = request.getSession();
		hs.setAttribute("login", false);
		return "main";
	}
}

 

'SPRING' 카테고리의 다른 글

230303_Tiles  (0) 2023.03.03
230302_Tiles  (0) 2023.03.02
230227_MyBatis  (0) 2023.02.27
230224_MyBatis  (0) 2023.02.24
230223_MyBatis  (0) 2023.02.23

댓글