일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- JPA프록시
- Git
- JPA값타입
- springbootH2
- spring
- springboot기본설정
- httppie
- 자바제너릭
- 스프링부트기본설정
- OSIV
- 에이치투데이터베이스
- 제이피큐엘쿼리
- dockercmd
- springbootproxy
- 임베디드타입
- JPAmapping
- MySqlType
- javageneric
- 데이터베이트h2
- jpa
- 스프링부트
- sql
- JPAproxy
- 이해와 원리
- jpqlquery
- Open EntityManager
- embededtype
- JDBC connection pool
- gitinitial
- JPA Hint & Lock
Archives
- Today
- Total
빡코
스프링 3.0 + 웹 개발 본문
프로젝트를 생성후 아래와 같이 세팅해준다
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.jdbc.springweb" />
<beans:bean id="boardDAO" class="com.jdbc.dao.BoardDAO">
<beans:property name="dataSource" ref="dataSource"/>
</beans:bean>
<!-- DB정보 -->
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<beans:property name="url" value="jdbc:oracle:thin:@192.168.16.16:1521:TestDB"/>
<beans:property name="username" value="SUZI"/>
<beans:property name="password" value="A123"/>
</beans:bean>
<beans:bean id="myUtil" class="com.jdbc.util.MyUtil"/>
</beans:beans>
pom.xml 파일 설정하기
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jdbc</groupId>
<artifactId>springweb</artifactId>
<name>Springweb</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<!-- dbcp -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- commons-pool -->
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<!-- ojdbc6 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>12.1.0.1-atlassian-hosted</version>
</dependency>
<!-- Spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
</dependencies>
<!-- ojdbc6 관련 주소 별도지정 -->
<repositories>
<repository>
<id>oracle</id>
<name>Oracle JDBC Repository</name>
<url>https://repo.spring.io/plugins-release/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
BoardDAO 코딩
package com.jdbc.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import com.jdbc.dto.BoardDTO;
public class BoardDAO {
private DataSource datasource;
public void setDataSource(DataSource datasource)
throws Exception{
this.datasource = datasource;
conn = datasource.getConnection();
}
Connection conn = null;
//1.num의 최대값
public int getMaxNum(){
int maxNum = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql;
try {
sql = "select nvl(max(num),0) from board";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
maxNum = rs.getInt(1);
rs.close();
pstmt.close();
} catch (Exception e) {
System.out.println(e.toString());
}
return maxNum;
}
//입력(created.jsp->created_ok.jsp)
public int insertData(BoardDTO dto){
int result = 0;
PreparedStatement pstmt = null;
String sql;
try {
sql = "insert into board (num,name,pwd,email,subject,content,";
sql+= "ipAddr,hitCount,created) ";
sql+= "values(?,?,?,?,?,?,?,0,sysdate)";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, dto.getNum());
pstmt.setString(2, dto.getName());
pstmt.setString(3, dto.getPwd());
pstmt.setString(4, dto.getEmail());
pstmt.setString(5, dto.getSubject());
pstmt.setString(6, dto.getContent());
pstmt.setString(7, dto.getIpAddr());
result = pstmt.executeUpdate();
pstmt.close();
} catch (Exception e) {
System.out.println(e.toString());
}
return result;
}
//전체데이터
public List<BoardDTO> getList(int start, int end,
String searchKey, String searchValue){
List<BoardDTO> lists = new ArrayList<BoardDTO>();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql;
try {
searchValue = "%" + searchValue + "%";
sql = "select * from (";
sql+= "select rownum rnum,data.* from(";
sql+= "select num,name,subject,hitCount,";
sql+= "to_char(created,'YYYY-MM-DD') created ";
sql+= "from board where " + searchKey + " like ? order by num desc) data) ";
sql+= "where rnum >= ? and rnum <= ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, searchValue);
pstmt.setInt(2, start);
pstmt.setInt(3, end);
rs = pstmt.executeQuery();
while(rs.next()){
BoardDTO dto = new BoardDTO();
dto.setNum(rs.getInt("num"));
dto.setName(rs.getString("name"));
dto.setSubject(rs.getString("subject"));
dto.setHitCount(rs.getInt("hitCount"));
dto.setCreated(rs.getString("created"));
lists.add(dto);
}
rs.close();
pstmt.close();
} catch (Exception e) {
System.out.println(e.toString());
}
return lists;
}
//전체 데이터수 구하기
public int getDataCount(String searchKey,String searchValue){
int result = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql;
try {
searchValue = "%" + searchValue + "%";
sql = "select nvl(count(*),0) from board ";
sql+= "where " + searchKey + " like ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, searchValue);
rs = pstmt.executeQuery();
if(rs.next()){
result = rs.getInt(1);
}
rs.close();
pstmt.close();
} catch (Exception e) {
System.out.println(e.toString());
}
return result;
}
//조회수증가
public int updateHitCount(int num){
int result = 0;
PreparedStatement pstmt = null;
String sql;
try {
sql = "update board set hitCount=hitCount + 1 where num=?";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, num);
result = pstmt.executeUpdate();
pstmt.close();
} catch (Exception e) {
System.out.println(e.toString());
}
return result;
}
//한명의 데이터 출력
public BoardDTO getReadData(int num){
BoardDTO dto = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql;
try {
sql = "select num,name,pwd,email,subject,content,ipAddr,";
sql+= "hitCount,created from board where num=?";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, num);
rs = pstmt.executeQuery();
if(rs.next()){
dto = new BoardDTO();
dto.setNum(rs.getInt("num"));
dto.setName(rs.getString("name"));
dto.setPwd(rs.getString("pwd"));
dto.setEmail(rs.getString("email"));
dto.setSubject(rs.getString("subject"));
dto.setContent(rs.getString("content"));
dto.setIpAddr(rs.getString("ipAddr"));
dto.setHitCount(rs.getInt("hitCount"));
dto.setCreated(rs.getString("created"));
}
rs.close();
pstmt.close();
} catch (Exception e) {
System.out.println(e.toString());
}
return dto;
}
//삭제
public int deleteData(int num){
int result = 0;
PreparedStatement pstmt = null;
String sql;
try {
sql = "delete board where num=?";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, num);
result = pstmt.executeUpdate();
pstmt.close();
} catch (Exception e) {
System.out.println(e.toString());
}
return result;
}
//수정
public int updateData(BoardDTO dto){
int result = 0;
PreparedStatement pstmt = null;
String sql;
try {
sql = "update board set name=?, pwd=?, email=?, subject=?,";
sql+= "content=? where num=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, dto.getName());
pstmt.setString(2, dto.getPwd());
pstmt.setString(3, dto.getEmail());
pstmt.setString(4, dto.getSubject());
pstmt.setString(5, dto.getContent());
pstmt.setInt(6, dto.getNum());
result = pstmt.executeUpdate();
pstmt.close();
} catch (Exception e) {
System.out.println(e.toString());
}
return result;
}
}
BoardDTO
package com.jdbc.dto;
public class BoardDTO {
private int num;
private String name,pwd,email,subject,content,ipAddr,created;
private int hitCount;
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 String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getIpAddr() {
return ipAddr;
}
public void setIpAddr(String ipAddr) {
this.ipAddr = ipAddr;
}
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
public int getHitCount() {
return hitCount;
}
public void setHitCount(int hitCount) {
this.hitCount = hitCount;
}
}
BoardContlolrer
package com.jdbc.springweb;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.jdbc.dao.BoardDAO;
import com.jdbc.dto.BoardDTO;
import com.jdbc.util.MyUtil;
@Controller
public class BoardController {
@Autowired
@Qualifier("boardDAO")
BoardDAO dao;
@Autowired
MyUtil myUtil;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home() {
return "index";
}
@RequestMapping(value = "/created.action", method = {RequestMethod.GET, RequestMethod.POST})
public String created(HttpServletRequest request, HttpServletResponse response) {
return "bbs/created";
}
@RequestMapping(value = "/created_ok.action", method = {RequestMethod.GET, RequestMethod.POST})
public String created_ok(BoardDTO dto,
HttpServletRequest request, HttpServletResponse response) {
int maxNum = dao.getMaxNum();
dto.setNum(maxNum + 1);
dto.setIpAddr(request.getRemoteAddr());
dao.insertData(dto); //dto5개 + 2 + 2
return "redirect:/list.action";
}
@RequestMapping(value = "/list.action", method = {RequestMethod.GET, RequestMethod.POST})
public String list(HttpServletRequest request, HttpServletResponse response)
throws UnsupportedEncodingException {
String cp = request.getContextPath();
String pageNum = request.getParameter("pageNum");
int currentPage = 1;
if(pageNum != null)
currentPage = Integer.parseInt(pageNum);
String searchKey = request.getParameter("searchKey");
String searchValue = request.getParameter("searchValue");
if(searchKey == null){
searchKey = "subject";
searchValue = "";
}else{
if(request.getMethod().equalsIgnoreCase("GET"))
searchValue =
URLDecoder.decode(searchValue, "UTF-8");
}
//전체데이터갯수
int dataCount = dao.getDataCount(searchKey, searchValue);
//전체페이지수
int numPerPage = 10;
int totalPage = myUtil.getPageCount(numPerPage, dataCount);
if(currentPage > totalPage)
currentPage = totalPage;
int start = (currentPage-1)*numPerPage+1;
int end = currentPage*numPerPage;
List<BoardDTO> lists =
dao.getList(start, end, searchKey, searchValue);
//페이징 처리
String param = "";
if(!searchValue.equals("")){
param = "searchKey=" + searchKey;
param+= "&searchValue="
+ URLEncoder.encode(searchValue, "UTF-8");
}
String listUrl = cp + "/list.action";
if(!param.equals("")){
listUrl = listUrl + "?" + param;
}
String pageIndexList =
myUtil.pageIndexList(currentPage, totalPage, listUrl);
//글보기 주소 정리
String articleUrl =
cp + "/article.action?pageNum=" + currentPage;
if(!param.equals(""))
articleUrl = articleUrl + "&" + param;
//포워딩 될 페이지에 데이터를 넘긴다
request.setAttribute("lists", lists);
request.setAttribute("pageIndexList",pageIndexList);
request.setAttribute("dataCount",dataCount);
request.setAttribute("articleUrl",articleUrl);
return "bbs/list";
}
@RequestMapping(value = "/article.action", method = {RequestMethod.GET, RequestMethod.POST})
public String article(HttpServletRequest request, HttpServletResponse response)
throws UnsupportedEncodingException {
int num = Integer.parseInt(request.getParameter("num"));
String pageNum = request.getParameter("pageNum");
String searchKey = request.getParameter("searchKey");
String searchValue = request.getParameter("searchValue");
if(searchKey != null)
searchValue = URLDecoder.decode(searchValue, "UTF-8");
//조회수 증가
dao.updateHitCount(num);
BoardDTO dto = dao.getReadData(num);
if(dto==null){
return "redirect:/list.action";
}
int lineSu = dto.getContent().split("\n").length;
dto.setContent(dto.getContent().replaceAll("\n", "<br/>"));
String param = "pageNum=" + pageNum;
if(searchKey!=null){
param += "&searchKey=" + searchKey;
param += "&searchValue="
+ URLEncoder.encode(searchValue, "UTF-8");
}
request.setAttribute("dto", dto);
request.setAttribute("params",param);
request.setAttribute("lineSu",lineSu);
request.setAttribute("pageNum",pageNum);
return "bbs/article";
}
@RequestMapping(value = "/updated.action", method = {RequestMethod.GET, RequestMethod.POST})
public String updated(HttpServletRequest request, HttpServletResponse response)
throws UnsupportedEncodingException {
int num = Integer.parseInt(request.getParameter("num"));
String pageNum = request.getParameter("pageNum");
BoardDTO dto = dao.getReadData(num);
if(dto == null){
return "redirect:/list.action";
}
request.setAttribute("dto", dto);
request.setAttribute("pageNum", pageNum);
return "bbs/updated";
}
@RequestMapping(value = "/updated_ok.action", method = {RequestMethod.GET, RequestMethod.POST})
public String updated_ok(BoardDTO dto,
HttpServletRequest request, HttpServletResponse response)
throws UnsupportedEncodingException {
String pageNum = request.getParameter("pageNum");
dao.updateData(dto); //넘어올때 5개 데이터 가져옴
return "redirect:/list.action?pageNum=" + pageNum;
}
@RequestMapping(value = "/deleted.action", method = {RequestMethod.GET, RequestMethod.POST})
public String deleted(HttpServletRequest request, HttpServletResponse response)
throws UnsupportedEncodingException {
String pageNum = request.getParameter("pageNum");
int num =Integer.parseInt(request.getParameter("num"));
dao.deleteData(num);
return "redirect:/list.action?pageNum=" + pageNum;
}
}
MyUtil
package com.jdbc.util;
public class MyUtil {
//전체 페이지수 구하기
//numPerPage : 한화면에 표시할 데이터의 갯수
//dataCount : 전체 데이터의 갯수
public int getPageCount(int numPerPage, int dataCount){
int pageCount = 0;
pageCount = dataCount / numPerPage;
if(dataCount % numPerPage != 0)
pageCount++;
return pageCount;
}
//페이징 처리 메소드
//currentPage :현재 표시할 페이지
//totalPage : 전체 페이지수
//listUrl : 링크를 설정할 url
public String pageIndexList(int currentPage, int totalPage, String listUrl){
int numPerBlock = 5; //1◀이전 6 7 8 9 10 다음▶11(6-10까지 표시되는 페이지 갯수)
int currentPageSetup; //표시할 첫 페이지(6)의 – 1 해준 값(5,10,15,20...)
int page;
StringBuffer sb = new StringBuffer();
if(currentPage==0 || totalPage==0) //데이터가 없을 경우
return "";
//abc.jsp?a=1
if(listUrl.indexOf("?") != -1) //주소줄에 ?표가 있다면
listUrl = listUrl + "&";
else
listUrl = listUrl + "?";
//표시할 첫 페이지의 – 1 해준 값
currentPageSetup = (currentPage/numPerBlock)*numPerBlock;
if(currentPage % numPerBlock == 0)
currentPageSetup = currentPageSetup - numPerBlock;
//◀이전
if(totalPage > numPerBlock && currentPageSetup > 0){
sb.append("<a href=\"" + listUrl + "pageNum="
+ currentPageSetup + "\">◀이전</a> ");
}
//바로가기 페이지
page = currentPageSetup + 1;
while(page <= totalPage && page <= (currentPageSetup + numPerBlock)){
if(page == currentPage){
sb.append("<font color=\"Fuchsia\">" + page + "</font> ");
}else{
sb.append("<a href=\"" + listUrl + "pageNum=" + page + "\">"
+ page + "</a> ");
}
page++;
}
//다음▶
if(totalPage - currentPageSetup > numPerBlock){
sb.append("<a href=\"" + listUrl + "pageNum=" + page + "\">다음▶</a> ");
}
return sb.toString();
}
}
list.jsp 파일
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="/springweb/resources/css/style.css" type="text/css"/>
<link rel="stylesheet" href="/springweb/resources/css/list.css" type="text/css"/>
<script type="text/javascript">
function sendIt(){
var f = document.searchForm;
f.action = "<%=cp%>/board/list.action";
f.submit();
}
</script>
</head>
<body>
<div id="bbsList">
<div id="bbsList_title">
게 시 판(Servlet)
</div>
<div id="bbsList_header">
<div id="leftHeader">
<form action="" name="searchForm" method="post">
<select name="searchKey" class="selectField">
<option value="subject">제목</option>
<option value="name">작성자</option>
<option value="content">내용</option>
</select>
<input type="text" name="searchValue" class="textField">
<input type="button" value=" 검색 " class="btn2" onclick="sendIt();"/>
</form>
</div>
<div id="rightHeader">
<input type="button" value=" 글올리기 " class="btn2"
onclick="javascript:location.href='<%=cp%>/created.action';"/>
</div>
</div>
<div id="bbsList_list">
<div id="title">
<dl>
<dt class="num">번호</dt>
<dt class="subject">제목</dt>
<dt class="name">작성자</dt>
<dt class="created">작성일</dt>
<dt class="hitCount">조회수</dt>
</dl>
</div>
<div id="lists">
<c:forEach var="dto" items="${lists}">
<dl>
<dd class="num">${dto.num }</dd>
<dd class="subject">
<a href="${articleUrl}&num=${dto.num}">
${dto.subject }</a></dd>
<dd class="name">${dto.name }</dd>
<dd class="created">${dto.created }</dd>
<dd class="hitCount">${dto.hitCount }</dd>
</dl>
</c:forEach>
</div>
<div id="footer">
<p>
<c:if test="${dataCount!=0 }">
${pageIndexList }
</c:if>
<c:if test="${dataCount==0 }">
등록된게시물이 없습니다.
</c:if>
</p>
</div>
</div>
</div>
</body>
</html>
article.jsp 파일
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="/springweb/resources/css/style.css" type="text/css"/>
<link rel="stylesheet" href="/springweb/resources/css/article.css" type="text/css"/>
</head>
<body>
<div id="bbs">
<div id="bbs_title">
게 시 판(Servlet)
</div>
<div id="bbsArticle">
<div id="bbsArticle_header">
${dto.subject }
</div>
<div class="bbsArticle_bottomLine">
<dl>
<dt>작성자</dt>
<dd>${dto.name }</dd>
<dt>줄수</dt>
<dd>${lineSu }</dd>
</dl>
</div>
<div class="bbsArticle_bottomLine">
<dl>
<dt>등록일</dt>
<dd>${dto.created }</dd>
<dt>조회수</dt>
<dd>${dto.hitCount }</dd>
</dl>
</div>
<div id="bbsArticle_content">
<table width="600" border="0">
<tr><td style="padding: 20px 80px 20px 62px;" valign="top" height="200">
${dto.content }
</td></tr>
</table>
</div>
</div>
<div class="bbsArticle_noLine" style="text-align: right;">
From : ${dto.ipAddr }
</div>
<div id="bbsArticle_footer">
<div id="leftFooter">
<input type="button" value=" 수정 " class="btn2"
onclick="javascript:location.href='<%=cp%>/updated.action?num=${dto.num}&pageNum=${pageNum}'"/>
<input type="button" value=" 삭제 " class="btn2"
onclick="javascript:location.href='<%=cp%>/deleted.action?num=${dto.num}&pageNum=${pageNum}'"/>
</div>
<div id="rightFooter">
<input type="button" value=" 리스트 " class="btn2"
onclick="javascript:location.href='<%=cp%>/list.action?${params}'"/>
</div>
</div>
</div>
</body>
</html>
created.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>게 시 판</title>
<link rel="stylesheet" href="/springweb/resources/css/style.css" type="text/css"/>
<link rel="stylesheet" href="/springweb/resources/css/created.css" type="text/css"/>
<script type="text/javascript" src="/springweb/resources/js/util.js"></script>
<script type="text/javascript">
function sendIt(){
f = document.myForm;
str = f.subject.value;
str = str.trim();
if(!str){
alert("\n제목을 입력하세요.");
f.subject.focus();
return;
}
f.subject.value = str;
str = f.name.value;
str = str.trim();
if(!str){
alert("\n이름을 입력하세요.");
f.name.focus();
return;
}
/*
if(!isValidKorean(str)){
alert("\n이름을 정확히 입력하세요.");
f.name.focus();
return;
}
*/
f.name.value = str;
if(f.email.value){
if(!isValidEmail(f.email.value)){
alert("\n정상적인 E-Mail을 입력하세요.");
f.email.focus();
return;
}
}
str = f.content.value;
str = str.trim();
if(!str){
alert("\n내용을 입력하세요.");
f.content.focus();
return;
}
f.content.value = str;
str = f.pwd.value;
str = str.trim();
if(!str){
alert("\n패스워드를 입력하세요.");
f.pwd.focus();
return;
}
f.pwd.value = str;
f.action = "<%=cp%>/created_ok.action";
f.submit();
}
</script>
</head>
<body>
<div id="bbs">
<div id="bbs_title">
게 시 판(Servlet)
</div>
<form action="" name="myForm" method="post">
<div id="bbsCreated">
<div class="bbsCreated_bottomLine">
<dl>
<dt>제 목</dt>
<dd>
<input type="text" name="subject" size="74" maxlength="100" class="boxTF"/>
</dd>
</dl>
</div>
<div class="bbsCreated_bottomLine">
<dl>
<dt>작성자</dt>
<dd>
<input type="text" name="name" size="35" maxlength="20" class="boxTF"/>
</dd>
</dl>
</div>
<div class="bbsCreated_bottomLine">
<dl>
<dt>E-Mail</dt>
<dd>
<input type="text" name="email" size="35" maxlength="50" class="boxTF"/>
</dd>
</dl>
</div>
<div id="bbsCreated_content" >
<dl>
<dt>내 용</dt>
<dd>
<textarea rows="12" cols="63" name="content" class="boxTA"></textarea>
</dd>
</dl>
</div>
<div class="bbsCreated_noLine">
<dl>
<dt>패스워드</dt>
<dd>
<input type="password" name="pwd" size="35" maxlength="7" class="boxTF"/>
</dd>
</dl>
</div>
</div>
<div id="bbsCreated_footer">
<input type="button" value=" 등록하기 " class="btn2"
onclick="sendIt();"/>
<input type="reset" value=" 다시입력 " class="btn2"
onclick="document.myForm.subject.focus();"/>
<input type="button" value=" 작성취소 " class="btn2"
onclick="javascript:location.href='<%=cp%>/list.action';"/>
</div>
</form>
</div>
</body>
</html>
update.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>게 시 판</title>
<link rel="stylesheet" href="/springweb/resources/css/style.css" type="text/css"/>
<link rel="stylesheet" href="/springweb/resources/css/created.css" type="text/css"/>
<script type="text/javascript" src="/springweb/resources/js/util.js"></script>
<script type="text/javascript">
function sendIt(){
f = document.myForm;
str = f.subject.value;
str = str.trim();
if(!str){
alert("\n제목을 입력하세요.");
f.subject.focus();
return;
}
f.subject.value = str;
str = f.name.value;
str = str.trim();
if(!str){
alert("\n이름을 입력하세요.");
f.name.focus();
return;
}
/*
if(!isValidKorean(str)){
alert("\n이름을 정확히 입력하세요.");
f.name.focus();
return;
}
*/
f.name.value = str;
if(f.email.value){
if(!isValidEmail(f.email.value)){
alert("\n정상적인 E-Mail을 입력하세요.");
f.email.focus();
return;
}
}
str = f.content.value;
str = str.trim();
if(!str){
alert("\n내용을 입력하세요.");
f.content.focus();
return;
}
f.content.value = str;
str = f.pwd.value;
str = str.trim();
if(!str){
alert("\n패스워드를 입력하세요.");
f.pwd.focus();
return;
}
f.pwd.value = str;
f.action = "<%=cp%>/updated_ok.action";
f.submit();
}
</script>
</head>
<body>
<div id="bbs">
<div id="bbs_title">
게 시 판(Servlet)
</div>
<form action="" name="myForm" method="post">
<div id="bbsCreated">
<div class="bbsCreated_bottomLine">
<dl>
<dt>제 목</dt>
<dd>
<input type="text" name="subject" value="${dto.subject }" size="74" maxlength="100" class="boxTF"/>
</dd>
</dl>
</div>
<div class="bbsCreated_bottomLine">
<dl>
<dt>작성자</dt>
<dd>
<input type="text" name="name" value="${dto.name }" size="35" maxlength="20" class="boxTF"/>
</dd>
</dl>
</div>
<div class="bbsCreated_bottomLine">
<dl>
<dt>E-Mail</dt>
<dd>
<input type="text" name="email" value="${dto.email }" size="35" maxlength="50" class="boxTF"/>
</dd>
</dl>
</div>
<div id="bbsCreated_content" >
<dl>
<dt>내 용</dt>
<dd>
<textarea rows="12" cols="63" name="content" class="boxTA">${dto.content }</textarea>
</dd>
</dl>
</div>
<div class="bbsCreated_noLine">
<dl>
<dt>패스워드</dt>
<dd>
<input type="password" name="pwd" value="${dto.pwd }" size="35" maxlength="7" class="boxTF"/>
</dd>
</dl>
</div>
</div>
<div id="bbsCreated_footer">
<input type="hidden" name="num" value="${dto.num }"/>
<input type="hidden" name="pageNum" value="${pageNum }"/>
<input type="button" value=" 수정하기 " class="btn2"
onclick="sendIt();"/>
<input type="button" value=" 수정취소 " class="btn2"
onclick="javascript:location.href='<%=cp%>/list.action';"/>
</div>
</form>
</div>
</body>
</html>
index.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>게 시 판</title>
<link rel="stylesheet" href="/springweb/resources/css/style.css" type="text/css"/>
<link rel="stylesheet" href="/springweb/resources/css/created.css" type="text/css"/>
<script type="text/javascript" src="/springweb/resources/js/util.js"></script>
<script type="text/javascript">
function sendIt(){
f = document.myForm;
str = f.subject.value;
str = str.trim();
if(!str){
alert("\n제목을 입력하세요.");
f.subject.focus();
return;
}
f.subject.value = str;
str = f.name.value;
str = str.trim();
if(!str){
alert("\n이름을 입력하세요.");
f.name.focus();
return;
}
/*
if(!isValidKorean(str)){
alert("\n이름을 정확히 입력하세요.");
f.name.focus();
return;
}
*/
f.name.value = str;
if(f.email.value){
if(!isValidEmail(f.email.value)){
alert("\n정상적인 E-Mail을 입력하세요.");
f.email.focus();
return;
}
}
str = f.content.value;
str = str.trim();
if(!str){
alert("\n내용을 입력하세요.");
f.content.focus();
return;
}
f.content.value = str;
str = f.pwd.value;
str = str.trim();
if(!str){
alert("\n패스워드를 입력하세요.");
f.pwd.focus();
return;
}
f.pwd.value = str;
f.action = "<%=cp%>/updated_ok.action";
f.submit();
}
</script>
</head>
<body>
<div id="bbs">
<div id="bbs_title">
게 시 판(Servlet)
</div>
<form action="" name="myForm" method="post">
<div id="bbsCreated">
<div class="bbsCreated_bottomLine">
<dl>
<dt>제 목</dt>
<dd>
<input type="text" name="subject" value="${dto.subject }" size="74" maxlength="100" class="boxTF"/>
</dd>
</dl>
</div>
<div class="bbsCreated_bottomLine">
<dl>
<dt>작성자</dt>
<dd>
<input type="text" name="name" value="${dto.name }" size="35" maxlength="20" class="boxTF"/>
</dd>
</dl>
</div>
<div class="bbsCreated_bottomLine">
<dl>
<dt>E-Mail</dt>
<dd>
<input type="text" name="email" value="${dto.email }" size="35" maxlength="50" class="boxTF"/>
</dd>
</dl>
</div>
<div id="bbsCreated_content" >
<dl>
<dt>내 용</dt>
<dd>
<textarea rows="12" cols="63" name="content" class="boxTA">${dto.content }</textarea>
</dd>
</dl>
</div>
<div class="bbsCreated_noLine">
<dl>
<dt>패스워드</dt>
<dd>
<input type="password" name="pwd" value="${dto.pwd }" size="35" maxlength="7" class="boxTF"/>
</dd>
</dl>
</div>
</div>
<div id="bbsCreated_footer">
<input type="hidden" name="num" value="${dto.num }"/>
<input type="hidden" name="pageNum" value="${pageNum }"/>
<input type="button" value=" 수정하기 " class="btn2"
onclick="sendIt();"/>
<input type="button" value=" 수정취소 " class="btn2"
onclick="javascript:location.href='<%=cp%>/list.action';"/>
</div>
</form>
</div>
</body>
</html>
'Java' 카테고리의 다른 글
Spring 3.0 View 셋팅 실습하기 (0) | 2019.11.15 |
---|---|
Spring 3.0 + Mybatis 셋팅 && 실습 (0) | 2019.11.15 |
Spring 3.0 + jdbc 셋팅 && 실습 (0) | 2019.11.15 |
스프링 3.0 + APO 셋팅 및 실습 (0) | 2019.11.14 |
스프링 3.0 + MyBatis 셋팅 (0) | 2019.11.14 |