-
[Spring] 스프링 게시판 만들기프로그래밍/Spring 2015. 9. 16. 22:22반응형
Spring MVC Framework 회원가입+로그인+게시판
1. Project Name : SummerBoard
2. JDK 7 이상
3. Apache Tomcat6,7
4. [web.xml]
123456789101112131415161718192021222324252627282930313233343536373839404142<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><display-name>SummerBoard</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><!-- filter declared --><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- Spring Dispatcher --><servlet><servlet-name>dispatcher</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class></servlet><servlet-mapping><servlet-name>dispatcher</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping></web-app>cs
5. DB 설계
12345678910111213141516171819202122232425262728293031323334create table JMBoard_Member0614(idx number primary key,userId varchar2(20) not null,userPw varchar2(20) not null,userName varchar2(50) not null,joinDate date not null)create sequence MEMBERSEQ0614;create table jmboard0614(idx number primary key,writer varchar2(50) not null,subject varchar2(100) not null,content varchar2(4000) not null,hitcount number default '0',recommendcount number default '0',,writeDate date not null,writerId varchar2(20) not null,fileName varchar2(50))create sequence BOARDLISTSEQ0614;create table jmboard_comment0614(idx number primary key,writer varchar2(50) not null,content varchar2(4000) not null,writeDate date not null,linkedArticleNum number not null,writerId varchar2(20) not null)create sequence BOARDCOMMENTSEQ0614;cs * iBatis 설정
[/src/config/dbconn.properties]
1234jdbc.driver = oracle.jdbc.driver.OracleDriverjdbc.url = jdbc:oracle:IPjdbc.username = IDjdbc.password = PWcs 드라이버, url, username, passwwrod는 설정한 내용을 기입한다.
[/src/config/sqlMapConfig.xml]
12345678910111213141516171819<!DOCTYPE sqlMapConfigPUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN""http://ibatis.apache.org/dtd/sql-map-config-2.dtd"><sqlMapConfig><settings useStatementNamespaces="true" /><transactionManager type="JDBC" commitRequired="false"><dataSource type="SIMPLE"><property name="JDBC.Driver" value="oracle.jdbc.driver.OracleDriver" /><property name="JDBC.ConnectionURL" value="jdbc:oracle:thin:@IP" /><property name="JDBC.Username" value="ID" /><property name="JDBC.Password" value="Password" /></dataSource></transactionManager><sqlMap resource="net/nice19/smboard/ibatis/member.xml" /><sqlMap resource="net/nice19/smboard/ibatis/board.xml" /><sqlMap resource="net/nice19/smboard/ibatis/login.xml" /></sqlMapConfig>cs 위의 각자 설정한대로 기입한다.
[/src/net.nice19.smboard/ibatis/login.xml]
1234567891011121314151617181920212223242526272829303132333435363738<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE sqlMapPUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN""http://ibatis.apache.org/dtd/sql-map-2.dtd"><sqlMap namespace="member"><typeAlias alias="MemberModel"type="net.nice19.smboard.member.model.MemberModel" /><select id="selectOneMember" parameterClass="int" resultClass="MemberModel">select idx, userId, userPw, userName, joinDatefrom JMBoard_Member0614where idx = #idx#</select><select id="selectAllMember" resultClass="MemberModel">select idx, userId,userPw, userName, joinDatefrom JMBoard_Member0614</select><select id="findByUserId" parameterClass="String" resultClass="MemberModel">selectidx,userId,userPw,userName,joinDatefrom JMBoard_Member0614where userId = #userId#</select><insert id="addMember" parameterClass="MemberModel">insert intoJMBoard_Member0614(idx, userId, userPw, userName, joinDate)values(MEMBERSEQ0614.nextVal, #userId#, #userPw#, #userName#, sysdate)</insert></sqlMap>cs [/src/net.nice19.smboard/ibatis/login.xml]
12345678910111213141516171819<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE sqlMapPUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN""http://ibatis.apache.org/dtd/sql-map-2.dtd"><sqlMap namespace="login"><typeAlias alias="LoginModel"type="net.nice19.smboard.login.model.LoginSessionModel" /><select id="loginCheck" parameterClass="String" resultClass="LoginModel">selectidx,userId,userPw,userName,joinDatefrom JMBoard_Member0614where userId = #userId#</select></sqlMap>cs [/src/net.nice19.smboard/ibatis/board.xml]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE sqlMapPUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN""http://ibatis.apache.org/dtd/sql-map-2.dtd"><sqlMap namespace="board"><typeAlias alias="BoardModel" type="net.nice19.smboard.board.model.BoardModel" /><typeAlias alias="BoardCommentModel"type="net.nice19.smboard.board.model.BoardCommentModel" /><select id="getBoardList" parameterClass="java.util.HashMap"resultClass="BoardModel">selectb.idx, b.writer, b.subject,b.content, b.hitcount,b.recommendcount,to_char(b.writedate, 'YYYY-MM-DD HH:MI:SS')writeDate,count(c.idx) as "comment",b.writerId, b.fileName, b.rnumfrom (selecta.idx, a.writer, a.subject,a.content, a.hitcount,a.recommendcount,a.writedate, a.writerId, a.fileName, rownum rnumfrom(selectidx, writer, subject,content, hitcount, recommendcount,writedate, writerId, fileNamefrom jmboard0614order by idx desc) a) b leftouter join jmboard_comment0614 c on b.idx = c.linkedarticlenumwherernum between #startArticleNum# and #endArticleNum#group byb.idx,b.writer, b.subject,b.content, b.hitcount, b.recommendcount,b.writedate, b.rnum, b.writerId, b.fileNameorder by b.idx desc</select><select id="getTotalNum" resultClass="int">selectcount(idx)fromjmboard0614</select><select id="getSearchTotalNum" resultClass="int">selectcount(idx)fromjmboard0614where $type$ like '%$keyword$%'</select><select id="searchArticle" parameterClass="java.util.HashMap"resultClass="BoardModel">selectb.idx, b.writer, b.subject,b.content, b.hitcount,b.recommendcount,to_char(b.writedate, 'YYYY-MM-DD HH:MI:SS')writeDate,count(c.idx) as "comment",b.writerId, b.fileName, b.rnumfrom (selecta.idx, a.writer, a.subject,a.content, a.hitcount,a.recommendcount,a.writedate, a.writerId, a.fileName, rownum rnumfrom(selectidx, writer, subject,content, hitcount, recommendcount,writedate, writerId, fileNamefrom jmboard0614where $type$ like'%$keyword$%'order by idx desc) a) b left outer joinjmboard_comment0614 c on b.idx = c.linkedarticlenumwhere rnum between#startArticleNum# and #endArticleNum#group byb.idx, b.writer,b.subject,b.content, b.hitcount, b.recommendcount,b.writedate, b.rnum,b.writerId, b.fileNameorder by b.idx desc</select><select id="getOneArticle" parameterClass="int" resultClass="BoardModel">selectidx,writer,subject,content,hitcount,recommendcount,writedate,writerId,fileNamefrom jmboard0614where idx = #idx#</select><select id="getCommentList" parameterClass="int" resultClass="BoardCommentModel">selectidx, writer, content,writeDate, linkedArticleNum, writerIdfromjmboard_comment0614where linkedArticleNum = #idx#order by idx desc</select><select id="getOneComment" parameterClass="int" resultClass="BoardCommentModel">selectidx, writer,content,writeDate, linkedArticleNum, writerIdfromjmboard_comment0614where idx = #idx#</select><insert id="writeArticle" parameterClass="BoardModel">insert intojmboard0614(idx, writer, subject, content, hitcount, recommendcount,writeDate, writerId, fileName)values(BOARDLISTSEQ0614.nextVal, #writer#,#subject#, #content#, 0, 0, sysdate, #writerId#,#fileName#)</insert><insert id="writeComment" parameterClass="BoardCommentModel">insert intojmboard_comment0614(idx, writer, content, writeDate, linkedArticleNum,writerId)values(BOARDCOMMENTSEQ0614.nextVal, #writer#, #content#, sysdate,#linkedArticleNum#, #writerId#)</insert><update id="updateHitcount" parameterClass="java.util.HashMap">updatejmboard0614sethitcount = #hitcount#where idx = #idx#</update><update id="updateRecommendcount" parameterClass="java.util.HashMap">updatejmboard0614set recommendcount = #recommendcount#where idx = #idx#</update><delete id="deleteComment" parameterClass="int">deletefromjmboard_comment0614where idx = #idx#</delete><delete id="deleteArticle" parameterClass="int">deletefrom jmboard0614where idx = #idx#</delete><update id="modifyArticle" parameterClass="BoardModel">update jmboard0614setsubject = #subject#,content = #content#,fileName = #fileName#where idx= #idx#</update></sqlMap>cs [/src/config/applicationContext.xml]
12345678910111213141516171819202122232425262728293031323334353637383940414243444546<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><!-- iBatis --><beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations" value="classpath:config/dbconn.properties" /></bean><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="driverClassName" value="${jdbc.driver}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /></bean><bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><property name="dataSource" ref="dataSource" /><property name="configLocation" value="classpath:/config/sqlMapConfig.xml" /></bean><bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate"><property name="sqlMapClient" ref="sqlMapClient" /></bean><!-- service class --><bean id="loginService" class="net.nice19.smboard.login.service.LoginService"><property name="sqlMapClientTemplate" ref="sqlMapClientTemplate" /></bean><bean id="memberService" class="net.nice19.smboard.member.service.MemberService"><property name="sqlMapClientTemplate" ref="sqlMapClientTemplate" /></bean><bean id="boardService" class="net.nice19.smboard.board.service.BoardService"><property name="sqlMapClientTemplate" ref="sqlMapClientTemplate" /></bean></beans>cs 6. [/WEB-INF/dispatcher-servlet.xml]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><!-- controllers --><bean id="loginController" class="net.nice19.smboard.login.controller.LoginController" /><bean id="memberController" class="net.nice19.smboard.member.controller.MemberController" /><bean id="boardController" class="net.nice19.smboard.board.controller.BoardController" /><!-- viewResolver --><bean id="vewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="viewClass"value="org.springframework.web.servlet.view.JstlView" /><property name="prefix" value="/WEB-INF/" /><property name="suffix" value=".jsp" /></bean><!-- validation massage --><bean id="messageSource"class="org.springframework.context.support.ResourceBundleMessageSource"><property name="basenames"><list><value>config.validation</value></list></property></bean><!-- interceptor --><bean id="multipartResolver"class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean><beanclass="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"><property name="interceptors"><list><ref bean="sessionInterceptor" /></list></property></bean><bean id="sessionInterceptor" class="net.nice19.smboard.interceptor.SessionInterceptor" /></beans>cs 7. [/src/config/validation.properties]
1required=필수 항목입니다.cs 8. SessionInterceptor
123456789101112131415161718192021222324252627282930313233343536373839404142package net.nice19.smboard.interceptor;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;public class SessionInterceptor extends HandlerInterceptorAdapter {@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws Exception {// check variableObject userId = request.getSession().getAttribute("userId");//// pass through when access login.do, join.doif (request.getRequestURI().equals("/SummerBoard/login.do")|| request.getRequestURI().equals("/SummerBoard/member/join.do")) {if (userId != null) {response.sendRedirect(request.getContextPath() + "/board/list.do");return true;} else {return true;}}//// where other pagesif (userId == null) {response.sendRedirect(request.getContextPath() + "/login.do");return false;} else {return true;}//}@Overridepublic void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception {}}cs 9. 로그인/로그아웃
[LoginSessionModel.java]
1234567891011121314151617181920212223242526272829303132333435363738394041package net.nice19.smboard.login.model;public class LoginSessionModel {private String userId;private String userPw;private String userName;private boolean auth;public String getUserId() {return userId;}public void setUserId(String userId) {this.userId = userId;}public String getUserPw() {return userPw;}public void setUserPw(String userPw) {this.userPw = userPw;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public boolean isAuth() {return auth;}public void setAuth(boolean auth) {this.auth = auth;}}cs [LoginDao.java]
12345678package net.nice19.smboard.login.dao;import net.nice19.smboard.login.model.LoginSessionModel;public interface LoginDao {LoginSessionModel checkUserId(String userId);}cs [LoginValidator.java]
1234567891011121314151617181920212223242526272829package net.nice19.smboard.login.service;import net.nice19.smboard.login.model.LoginSessionModel;import org.springframework.validation.Errors;import org.springframework.validation.Validator;public class LoginValidator implements Validator {@Overridepublic boolean supports(Class<?> clazz) {return LoginSessionModel.class.isAssignableFrom(clazz);}@Overridepublic void validate(Object target, Errors errors) {LoginSessionModel loginModel = (LoginSessionModel) target;// check userId fieldif (loginModel.getUserId() == null || loginModel.getUserId().trim().isEmpty()) {errors.rejectValue("userId", "required");}// check userPw fieldif (loginModel.getUserPw() == null || loginModel.getUserPw().trim().isEmpty()) {errors.rejectValue("userPw", "required");}}}cs [LoginService.java]
1234567891011121314151617181920package net.nice19.smboard.login.service;import org.springframework.orm.ibatis.SqlMapClientTemplate;import net.nice19.smboard.login.dao.LoginDao;import net.nice19.smboard.login.model.LoginSessionModel;public class LoginService implements LoginDao {private SqlMapClientTemplate sqlMapClientTemplate;public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {this.sqlMapClientTemplate = sqlMapClientTemplate;}@Overridepublic LoginSessionModel checkUserId(String userId) {return (LoginSessionModel) sqlMapClientTemplate.queryForObject("login.loginCheck", userId);}}cs [LoginController.java]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172package net.nice19.smboard.login.controller;import javax.servlet.http.HttpSession;import net.nice19.smboard.login.model.LoginSessionModel;import net.nice19.smboard.login.service.LoginService;import net.nice19.smboard.login.service.LoginValidator;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.stereotype.Controller;import org.springframework.validation.BindingResult;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.ModelAndView;@Controllerpublic class LoginController {private ApplicationContext context;@RequestMapping("/login.do")public String login() {return "/board/login";}@RequestMapping(value = "/login.do", method = RequestMethod.POST)public ModelAndView loginProc(@ModelAttribute("LoginModel") LoginSessionModel loginModel, BindingResult result,HttpSession session) {ModelAndView mav = new ModelAndView();// form validationnew LoginValidator().validate(loginModel, result);if (result.hasErrors()) {mav.setViewName("/board/login");return mav;}String userId = loginModel.getUserId();String userPw = loginModel.getUserPw();context = new ClassPathXmlApplicationContext("/config/applicationContext.xml");LoginService loginService = (LoginService) context.getBean("loginService");LoginSessionModel loginCheckResult = loginService.checkUserId(userId);// check joined userif (loginCheckResult == null) {mav.addObject("userId", userId);mav.addObject("errCode", 1); // not exist userId in databasemav.setViewName("/board/login");return mav;}// check passwordif (loginCheckResult.getUserPw().equals(userPw)) {session.setAttribute("userId", userId);session.setAttribute("userName", loginCheckResult.getUserName());mav.setViewName("redirect:/board/list.do");return mav;} else {mav.addObject("userId", userId);mav.addObject("errCode", 2); // not matched passwordmav.setViewName("/board/login");return mav;}}@RequestMapping("/logout.do")public String logout(HttpSession session) {session.invalidate();return "redirect:login.do";}}cs 10.회원가입
[MemberModel.java]
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849package net.nice19.smboard.member.model;public class MemberModel {private int idx;private String userId;private String userPw;private String userName;private String joinDate;public int getIdx() {return idx;}public void setIdx(int idx) {this.idx = idx;}public String getUserId() {return userId;}public void setUserId(String userId) {this.userId = userId;}public String getUserPw() {return userPw;}public void setUserPw(String userPw) {this.userPw = userPw;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getJoinDate() {return joinDate;}public void setJoinDate(String joinDate) {this.joinDate = joinDate;}}cs [MemberDao.java]
12345678910package net.nice19.smboard.member.dao;import net.nice19.smboard.member.model.MemberModel;public interface MemberDao {boolean addMember(MemberModel memberModel);MemberModel findByUserId(String userId);}cs [MemberValidatior.java]
123456789101112131415161718192021222324252627282930package net.nice19.smboard.member.service;import net.nice19.smboard.member.model.MemberModel;import org.springframework.validation.Errors;import org.springframework.validation.Validator;public class MemberValidatior implements Validator {@Overridepublic boolean supports(Class<?> clazz) {return MemberModel.class.isAssignableFrom(clazz);}@Overridepublic void validate(Object target, Errors errors) {MemberModel memberModel = (MemberModel) target;if (memberModel.getUserId() == null || memberModel.getUserId().trim().isEmpty()) {errors.rejectValue("userId", "required");}if (memberModel.getUserPw() == null || memberModel.getUserPw().trim().isEmpty()) {errors.rejectValue("userPw", "required");}if (memberModel.getUserName() == null || memberModel.getUserName().trim().isEmpty()) {errors.rejectValue("userName", "required");}}}cs [MemberService.java]
123456789101112131415161718192021222324252627282930313233package net.nice19.smboard.member.service;import org.springframework.orm.ibatis.SqlMapClientTemplate;import net.nice19.smboard.member.dao.MemberDao;import net.nice19.smboard.member.model.MemberModel;public class MemberService implements MemberDao {private SqlMapClientTemplate sqlMapClientTemplate;public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {this.sqlMapClientTemplate = sqlMapClientTemplate;}@Overridepublic boolean addMember(MemberModel memberModel) {sqlMapClientTemplate.insert("member.addMember", memberModel);MemberModel checkAddMember = findByUserId(memberModel.getUserId());// check addMember Processif (checkAddMember == null) {return false;} else {return true;}}@Overridepublic MemberModel findByUserId(String userId) {return (MemberModel) sqlMapClientTemplate.queryForObject("member.findByUserId", userId);}}cs [MemberController.java]
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758package net.nice19.smboard.member.controller;import net.nice19.smboard.member.model.MemberModel;import net.nice19.smboard.member.service.MemberService;import net.nice19.smboard.member.service.MemberValidatior;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.stereotype.Controller;import org.springframework.validation.BindingResult;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.ModelAndView;@Controller@RequestMapping("/member")public class MemberController {private ApplicationContext context;@RequestMapping("/join.do")public String memberJoin() {return "/board/join";}@RequestMapping(value = "/join.do", method = RequestMethod.POST)public ModelAndView addMember(@ModelAttribute("MemberModel") MemberModel memberModel, BindingResult result) {ModelAndView mav = new ModelAndView();new MemberValidatior().validate(memberModel, result);if (result.hasErrors()) {mav.setViewName("/board/join");return mav;}context = new ClassPathXmlApplicationContext("/config/applicationContext.xml");MemberService memberService = (MemberService) context.getBean("memberService");MemberModel checkMemberModel = memberService.findByUserId(memberModel.getUserId());if (checkMemberModel != null) {mav.addObject("errCode", 1); // userId already existmav.setViewName("/board/join");return mav;}if (memberService.addMember(memberModel)) {mav.addObject("errCode", 3);mav.setViewName("/board/login"); // success to add new member; move// to login pagereturn mav;} else {mav.addObject("errCode", 2); // failed to add new membermav.setViewName("/board/join");return mav;}}}cs 11.게시판
[BoardModel.java]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103package net.nice19.smboard.board.model;public class BoardModel {private int rnum;private int idx;private String writer;private String subject;private String content;private int hitcount = 0;private int recommendcount = 0;private int comment = 0;private String writeDate;private String writerId;private String fileName;public int getRnum() {return rnum;}public void setRnum(int rnum) {this.rnum = rnum;}public int getIdx() {return idx;}public void setIdx(int idx) {this.idx = idx;}public String getWriter() {return writer;}public void setWriter(String writer) {this.writer = writer;}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 int getHitcount() {return hitcount;}public void setHitcount(int hitcount) {this.hitcount = hitcount;}public int getRecommendcount() {return recommendcount;}public void setRecommendcount(int recommendcount) {this.recommendcount = recommendcount;}public int getComment() {return comment;}public void setComment(int comment) {this.comment = comment;}public String getWriteDate() {return writeDate;}public void setWriteDate(String writeDate) {this.writeDate = writeDate;}public String getWriterId() {return writerId;}public void setWriterId(String writerId) {this.writerId = writerId;}public String getFileName() {return fileName;}public void setFileName(String fileName) {this.fileName = fileName;}}cs [BoardCommentModel.java]
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758package net.nice19.smboard.board.model;public class BoardCommentModel {private int idx;private String writer;private String content;private String writeDate;private int linkedArticleNum;private String writerId;public int getIdx() {return idx;}public void setIdx(int idx) {this.idx = idx;}public String getWriter() {return writer;}public void setWriter(String writer) {this.writer = writer;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}public String getWriteDate() {return writeDate;}public void setWriteDate(String writeDate) {this.writeDate = writeDate;}public int getLinkedArticleNum() {return linkedArticleNum;}public void setLinkedArticleNum(int linkedArticleNum) {this.linkedArticleNum = linkedArticleNum;}public String getWriterId() {return writerId;}public void setWriterId(String writerId) {this.writerId = writerId;}}cs [BoardDao.java]
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950package net.nice19.smboard.board.dao;import java.util.List;import net.nice19.smboard.board.model.BoardCommentModel;import net.nice19.smboard.board.model.BoardModel;public interface BoardDao {// get all contents in JMBoard tableList<BoardModel> getBoardList(int startArticleNum, int showArticleLimit);// show detail about selected articleBoardModel getOneArticle(int idx);// get search result listList<BoardModel> searchArticle(String type, String keyword, int startArticleNum, int endArticleNum);// get all commentsList<BoardCommentModel> getCommentList(int idx);// get a commentBoardCommentModel getOneComment(int idx);// modify(update) articleboolean modifyArticle(BoardModel board);// insert article databoolean writeArticle(BoardModel board);// insert comment databoolean writeComment(BoardCommentModel comment);// update hitcountvoid updateHitcount(int hitcount, int idx);// update recommendcountvoid updateRecommendCount(int recommendcount, int idx);// get contents countint getTotalNum();// get count of search resultsint getSearchTotalNum(String type, String keyword);// delete a commentvoid deleteComment(int idx);// delete a articlevoid deleteArticle(int idx);}cs [BoardService.java]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106package net.nice19.smboard.board.service;import java.util.HashMap;import java.util.List;import org.springframework.orm.ibatis.SqlMapClientTemplate;import net.nice19.smboard.board.dao.BoardDao;import net.nice19.smboard.board.model.BoardCommentModel;import net.nice19.smboard.board.model.BoardModel;public class BoardService implements BoardDao {private SqlMapClientTemplate sqlMapClientTemplate;private HashMap<String, Object> valueMap = new HashMap<String, Object>();public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {this.sqlMapClientTemplate = sqlMapClientTemplate;}@Overridepublic List<BoardModel> getBoardList(int startArticleNum, int endArticleNum) {valueMap.put("startArticleNum", startArticleNum);valueMap.put("endArticleNum", endArticleNum);return sqlMapClientTemplate.queryForList("board.getBoardList", valueMap);}@Overridepublic BoardModel getOneArticle(int idx) {return (BoardModel) sqlMapClientTemplate.queryForObject("board.getOneArticle", idx);}@Overridepublic List<BoardModel> searchArticle(String type, String keyword, int startArticleNum, int endArticleNum) {valueMap.put("type", type);valueMap.put("keyword", keyword);valueMap.put("startArticleNum", startArticleNum);valueMap.put("endArticleNum", endArticleNum);return sqlMapClientTemplate.queryForList("board.searchArticle", valueMap);}@Overridepublic List<BoardCommentModel> getCommentList(int idx) {return sqlMapClientTemplate.queryForList("board.getCommentList", idx);}@Overridepublic boolean writeArticle(BoardModel board) {sqlMapClientTemplate.insert("board.writeArticle", board);return true;}@Overridepublic boolean writeComment(BoardCommentModel comment) {sqlMapClientTemplate.insert("board.writeComment", comment);return true;}@Overridepublic void updateHitcount(int hitcount, int idx) {valueMap.put("hitcount", hitcount);valueMap.put("idx", idx);sqlMapClientTemplate.update("board.updateHitcount", valueMap);}@Overridepublic void updateRecommendCount(int recommendcount, int idx) {valueMap.put("recommendcount", recommendcount);valueMap.put("idx", idx);sqlMapClientTemplate.update("board.updateRecommendcount", valueMap);}@Overridepublic int getTotalNum() {return (Integer) sqlMapClientTemplate.queryForObject("board.getTotalNum");}@Overridepublic int getSearchTotalNum(String type, String keyword) {valueMap.put("type", type);valueMap.put("keyword", keyword);return (Integer) sqlMapClientTemplate.queryForObject("board.getSearchTotalNum", valueMap);}@Overridepublic void deleteComment(int idx) {sqlMapClientTemplate.delete("board.deleteComment", idx);}@Overridepublic void deleteArticle(int idx) {sqlMapClientTemplate.delete("board.deleteArticle", idx);}@Overridepublic BoardCommentModel getOneComment(int idx) {return (BoardCommentModel) sqlMapClientTemplate.queryForObject("board.getOneComment", idx);}@Overridepublic boolean modifyArticle(BoardModel board) {sqlMapClientTemplate.update("board.modifyArticle", board);return true;}}cs [BoardController.java]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378package net.nice19.smboard.board.controller;import java.io.File;import java.util.Date;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import net.nice19.smboard.board.model.BoardCommentModel;import net.nice19.smboard.board.model.BoardModel;import net.nice19.smboard.board.service.BoardService;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.multipart.MultipartFile;import org.springframework.web.multipart.MultipartHttpServletRequest;import org.springframework.web.servlet.ModelAndView;@Controller@RequestMapping("/board")public class BoardController {// DIprivate ApplicationContext context = new ClassPathXmlApplicationContext("/config/applicationContext.xml");private BoardService boardService = (BoardService) context.getBean("boardService");//// * User variable// article, page variablesprivate int currentPage = 1;private int showArticleLimit = 10; // change value if want to show more// articles by one pageprivate int showPageLimit = 10; // change value if want to show more page// linksprivate int startArticleNum = 0;private int endArticleNum = 0;private int totalNum = 0;//// file upload pathprivate String uploadPath = "C:\\Java\\JavaWeb15\\App\\SummerBoard\\WebContent\\files\\";////@RequestMapping("/list.do")public ModelAndView boardList(HttpServletRequest request, HttpServletResponse response) {String type = null;String keyword = null;// set variables from request parameterif (request.getParameter("page") == null || request.getParameter("page").trim().isEmpty()|| request.getParameter("page").equals("0")) {currentPage = 1;} else {currentPage = Integer.parseInt(request.getParameter("page"));}if (request.getParameter("type") != null) {type = request.getParameter("type").trim();}if (request.getParameter("keyword") != null) {keyword = request.getParameter("keyword").trim();}//// expression article variables valuestartArticleNum = (currentPage - 1) * showArticleLimit + 1;endArticleNum = startArticleNum + showArticleLimit - 1;//// get boardList and get page html codeList<BoardModel> boardList;if (type != null && keyword != null) {boardList = boardService.searchArticle(type, keyword, startArticleNum, endArticleNum);totalNum = boardService.getSearchTotalNum(type, keyword);} else {boardList = boardService.getBoardList(startArticleNum, endArticleNum);totalNum = boardService.getTotalNum();}StringBuffer pageHtml = getPageHtml(currentPage, totalNum, showArticleLimit, showPageLimit, type, keyword);//ModelAndView mav = new ModelAndView();mav.addObject("boardList", boardList);mav.addObject("pageHtml", pageHtml);mav.setViewName("/board/list");return mav;}// A method for Creating page html codeprivate StringBuffer getPageHtml(int currentPage, int totalNum, int showArticleLimit, int showPageLimit,String type, String keyword) {StringBuffer pageHtml = new StringBuffer();int startPage = 0;int lastPage = 0;// expression page variablesstartPage = ((currentPage - 1) / showPageLimit) * showPageLimit + 1;lastPage = startPage + showPageLimit - 1;if (lastPage > totalNum / showArticleLimit) {lastPage = (totalNum / showArticleLimit) + 1;}//// create page html code// if: when no searchif (type == null && keyword == null) {if (currentPage == 1) {pageHtml.append("<span>");} else {pageHtml.append("<span><a href=\"list.do?page=" + (currentPage - 1) + "\"><이전></a> ");}for (int i = startPage; i <= lastPage; i++) {if (i == currentPage) {pageHtml.append(". <strong>");pageHtml.append("<a href=\"list.do?page=" + i + "\" class=\"page\">" + i + "</a>");pageHtml.append(" </strong>");} else {pageHtml.append(". <a href=\"list.do?page=" + i + "\" class=\"page\">" + i + "</a> ");}}if (currentPage == lastPage) {pageHtml.append(".</span>");} else {pageHtml.append(". <a href=\"list.do?page=" + (currentPage + 1) + "\"><다음></a></span>");}//// else: when search} else {if (currentPage == 1) {pageHtml.append("<span>");} else {pageHtml.append("<span><a href=\"list.do?page=" + (currentPage - 1) + "&type=" + type + "&keyword="+ keyword + "\"><이전></a> ");}for (int i = startPage; i <= lastPage; i++) {if (i == currentPage) {pageHtml.append(". <strong>");pageHtml.append("<a href=\"list.do?page=" + i + "&type=" + type + "&keyword=" + keyword+ "\" class=\"page\">" + i + "</a> ");pageHtml.append(" </strong>");} else {pageHtml.append(". <a href=\"list.do?page=" + i + "&type=" + type + "&keyword=" + keyword+ "\" class=\"page\">" + i + "</a> ");}}if (currentPage == lastPage) {pageHtml.append("</span>");} else {pageHtml.append(". <a href=\"list.do?page=" + (currentPage + 1) + "&type=" + type+ "&keyword=" + keyword + "\"><다음></a></span>");}}//return pageHtml;}@RequestMapping("/view.do")public ModelAndView boardView(HttpServletRequest request) {int idx = Integer.parseInt(request.getParameter("idx"));BoardModel board = boardService.getOneArticle(idx); // get selected// article modelboardService.updateHitcount(board.getHitcount() + 1, idx); // update// hitcountList<BoardCommentModel> commentList = boardService.getCommentList(idx); // get// comment// listModelAndView mav = new ModelAndView();mav.addObject("board", board);mav.addObject("commentList", commentList);mav.setViewName("/board/view");return mav;}@RequestMapping("/write.do")public String boardWrite(@ModelAttribute("BoardModel") BoardModel boardModel) {return "/board/write";}@RequestMapping(value = "/write.do", method = RequestMethod.POST)public String boardWriteProc(@ModelAttribute("BoardModel") BoardModel boardModel,MultipartHttpServletRequest request) {// get upload fileMultipartFile file = request.getFile("file");String fileName = file.getOriginalFilename();File uploadFile = new File(uploadPath + fileName);// when file exists as same nameif (uploadFile.exists()) {fileName = new Date().getTime() + fileName;uploadFile = new File(uploadPath + fileName);}// save upload file to uploadPathtry {file.transferTo(uploadFile);} catch (Exception e) {}boardModel.setFileName(fileName);//// new line code change to <br /> tagString content = boardModel.getContent().replaceAll("\r\n", "<br />");boardModel.setContent(content);//boardService.writeArticle(boardModel);return "redirect:list.do";}@RequestMapping("/commentWrite.do")public ModelAndView commentWriteProc(@ModelAttribute("CommentModel") BoardCommentModel commentModel) {// new line code change to <br /> tagString content = commentModel.getContent().replaceAll("\r\n", "<br />");commentModel.setContent(content);//boardService.writeComment(commentModel);ModelAndView mav = new ModelAndView();mav.addObject("idx", commentModel.getLinkedArticleNum());mav.setViewName("redirect:view.do");return mav;}@RequestMapping("/modify.do")public ModelAndView boardModify(HttpServletRequest request, HttpSession session) {String userId = (String) session.getAttribute("userId");int idx = Integer.parseInt(request.getParameter("idx"));BoardModel board = boardService.getOneArticle(idx);// <br /> tag change to new line codeString content = board.getContent().replaceAll("<br />", "\r\n");board.setContent(content);//ModelAndView mav = new ModelAndView();if (!userId.equals(board.getWriterId())) {mav.addObject("errCode", "1"); // forbidden connectionmav.addObject("idx", idx);mav.setViewName("redirect:view.do");} else {mav.addObject("board", board);mav.setViewName("/board/modify");}return mav;}@RequestMapping(value = "/modify.do", method = RequestMethod.POST)public ModelAndView boardModifyProc(@ModelAttribute("BoardModel") BoardModel boardModel,MultipartHttpServletRequest request) {String orgFileName = request.getParameter("orgFile");MultipartFile newFile = request.getFile("newFile");String newFileName = newFile.getOriginalFilename();boardModel.setFileName(orgFileName);// if: when want to change upload fileif (newFile != null && !newFileName.equals("")) {if (orgFileName != null || !orgFileName.equals("")) {// remove uploaded fileFile removeFile = new File(uploadPath + orgFileName);removeFile.delete();//}// create new upload fileFile newUploadFile = new File(uploadPath + newFileName);try {newFile.transferTo(newUploadFile);} catch (Exception e) {e.printStackTrace();}//boardModel.setFileName(newFileName);}//// new line code change to <br /> tagString content = boardModel.getContent().replaceAll("\r\n", "<br />");boardModel.setContent(content);//boardService.modifyArticle(boardModel);ModelAndView mav = new ModelAndView();mav.addObject("idx", boardModel.getIdx());mav.setViewName("redirect:/board/view.do");return mav;}@RequestMapping("/delete.do")public ModelAndView boardDelete(HttpServletRequest request, HttpSession session) {String userId = (String) session.getAttribute("userId");int idx = Integer.parseInt(request.getParameter("idx"));BoardModel board = boardService.getOneArticle(idx);ModelAndView mav = new ModelAndView();if (!userId.equals(board.getWriterId())) {mav.addObject("errCode", "1"); // it's forbidden connectionmav.addObject("idx", idx);mav.setViewName("redirect:view.do");} else {List<BoardCommentModel> commentList = boardService.getCommentList(idx); // check// commentsif (commentList.size() > 0) {mav.addObject("errCode", "2"); // can't delete because a article// has commentsmav.addObject("idx", idx);mav.setViewName("redirect:view.do");} else {// if: when the article has upload file - remove thatif (board.getFileName() != null) {File removeFile = new File(uploadPath + board.getFileName());removeFile.delete();}//boardService.deleteArticle(idx);mav.setViewName("redirect:list.do");}}return mav;}@RequestMapping("/commentDelete.do")public ModelAndView commendDelete(HttpServletRequest request, HttpSession session) {int idx = Integer.parseInt(request.getParameter("idx"));int linkedArticleNum = Integer.parseInt(request.getParameter("linkedArticleNum"));String userId = (String) session.getAttribute("userId");BoardCommentModel comment = boardService.getOneComment(idx);ModelAndView mav = new ModelAndView();if (!userId.equals(comment.getWriterId())) {mav.addObject("errCode", "1");} else {boardService.deleteComment(idx);}mav.addObject("idx", linkedArticleNum); // move back to the articlemav.setViewName("redirect:view.do");return mav;}@RequestMapping("/recommend.do")public ModelAndView updateRecommendcount(HttpServletRequest request, HttpSession session) {int idx = Integer.parseInt(request.getParameter("idx"));String userId = (String) session.getAttribute("userId");BoardModel board = boardService.getOneArticle(idx);ModelAndView mav = new ModelAndView();if (userId.equals(board.getWriterId())) {mav.addObject("errCode", "1");} else {boardService.updateRecommendCount(board.getRecommendcount() + 1, idx);}mav.addObject("idx", idx);mav.setViewName("redirect:/board/view.do");return mav;}}cs 12. 웹관련 파일
[/WebContent/css/board.css]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183body {background-color: #cccccc;font-family: sans-serif, tahoma, gulim;font-size: 10pt;}div.navBar {width: 100%;margin-top: 20px;}div.navBar ul {list-style: none;}div.navBar li {float: left;list-style-position: inside;padding-left: 20px;padding-right: 20px;}div.wrapper {width: 60%;margin: 0 auto;text-align: center;}.wrapper form fieldset {margin: 0 auto;height: 20px;margin-left: 60%;padding: 10px 10px 10px 10px;border-style: inherit;}.wrapper input.writeBt {height: 35px;width: 100px;}.wrapper input.boardSubject{width: 85%;height: 20px;margin-right: 5%;}.wrapper textarea.boardContent{width: 85%;height: 300px;margin-right: 5%;}table.boardTable {width: 100%;border-style: inherit;vertical-align: top;}.boardTable th{height: 35px;background-color: #b0e0e6;padding: 2px 2px 2px 2px;}.boardTable td{height: 30px;background-color: white;border-bottom-style: outset;padding: 2px 10px 2px 10px;}.boardTable td.idx{width: 7%;}.boardTable td.subject{width: 45%;}.boardTable td.writer{width: 10%;}.boardTable td.comment{width: 7%;}.boardTable td.hitcount{width: 7%;}.boardTable td.recommendcount{width: 7%;}.boardTable td.writeDate{width: 17%;}table.boardWrite{width: 100%;border-style: inherit;vertical-align: top;background-color: white;}table.boardWrite th{width: 15%;height: 35px;background-color: #b0e0e6;padding: 2px 2px 2px 2px;}table.boardWrite td{width: 85%;height: 35px;padding: 2px 2px 2px 2px;}table.boardView {width: 100%;border-style: inherit;vertical-align: top;}.boardView th{height: 25px;background-color: #b0e0e6;padding: 5px 5px 5px 5px;}.boardView td{height: 20px;background-color: white;padding: 5px 10px 5px 10px;}table.commentView {width: 100%;border-style: none;}.commentView th{height: 25px;background-color: #b0e0e6;padding: 5px 5px 5px 5px;}.commentView td.writer{width: 20%;background-color: white;padding: 5px 10px 5px 10px;}.commentView td.content{width: 80%;background-color: white;padding: 5px 10px 5px 10px;}textarea.commentForm{width: 80%;height: 50px;}input.commentBt{margin-left: 2%;width: 15%;}span.date {font-size: 8pt;color: #666666;}A:link { color: black; text-decoration:none; }A:visited { color: black; text-decoration:none; }A:active { color: black; text-decoration:none; }A:hover { color: #666666; text-decoration:none; }A.page:link { font-size: 11pt; color: black; text-decoration:none; }A.page:visited { font-size: 11pt; color: black; text-decoration:none; }A.page:active { font-size: 11pt; color: black; text-decoration:none; }A.page:hover { font-size: 11pt; color: #666666; text-decoration:none; }cs
[/WEB-INF/board/login.jsp]1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%><%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><!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>Login</title><link href="<%=request.getContextPath()%>/css/main.css" rel="stylesheet" type="text/css"><c:if test="${errCode == null}"><c:set var="errCode" value="\"\""></c:set></c:if><script type="text/javascript">function checkErrCode(){var errCode = ${errCode};if(errCode != null || errCode != ""){switch (errCode) {case 1:alert("가입된 이메일 주소가 아닙니다!");break;case 2:alert("비밀번호가 일치하지 않습니다!");break;case 3:alert("회원가입 처리가 완료되었습니다! 로그인 해 주세요!");location.href = "<%=request.getContextPath()%>/login.do";break;}}}</script></head><body onload="checkErrCode()"><div class="wrapper"><h3>스프링 게시판</h3><spring:hasBindErrors name="LoginModel" /><form:errors path="LoginModel" /><form action="login.do" method="post"><fieldset><label for="userId">메일주소 : </label><input type="text" id="userId" name="userId" class="loginInput" value="${userId}" /><span class="error"><form:errors path="LoginModel.userId" /></span><br /><label for="userPw">비밀번호 : </label><input type="password" id="userPw" name="userPw" class="loginInput"/><span class="error"><form:errors path="LoginModel.userPw" /></span><br /><br /><center><input type="submit" value="로그인" class="submitBt"/><br /><br /><a href="<%=request.getContextPath()%>/member/join.do">회원가입</a></center></fieldset></form></div></body></html>cs [/WEB-INF/board/join.jsp]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%><%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><!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>Join Member!</title><link href="<%=request.getContextPath()%>/css/main.css" rel="stylesheet"type="text/css"><script type="text/javascript"src="<%=request.getContextPath()%>/js/jquery-1.7.1.js"></script><c:if test="${errCode == null}"><c:set var="errCode" value="\"\""></c:set></c:if><script type="text/javascript">function errCodeCheck() {var errCode = ${errCode};if (errCode != null || errCode != "") {switch (errCode) {case 1:alert("이미 가입된 이메일 주소입니다!");break;case 2:alert("회원가입 처리가 실패하였습니다. 잠시 후 다시 시도해 주십시오.");break;}}}function passwordCheck() {if ($("#userPw").val() != $("#userPwCheck").val()) {alert("패스워드 입력이 일치하지 않습니다");$("#userPwCheck").focus();return false;}return true;}</script></head><body onload="errCodeCheck()"><div class="wrapper"><h3>회원가입</h3><spring:hasBindErrors name="MemberModel" /><form:errors path="MemberModel" /><form action="join.do" method="post" onsubmit="return passwordCheck()"><fieldset><label for="userId"> 메일주소 : </label> <input type="text"id="userId" name="userId" class="loginInput" /> <span class="error"><form:errorspath="MemberModel.userId" /></span><br /> <label for="userPw"> 비밀번호: </label> <input type="password" id="userPw" name="userPw"class="loginInput" /> <span class="error"><form:errorspath="MemberModel.userPw" /></span><br /> <label for="userPwCheck"> 비밀번호확인 : </label> <input type="password" id="userPwCheck" name="userPwCheck"class="loginInput" /><br /> <label for="userName"> 회원이름: </label> <input type="text" id="userName" name="userName"class="loginInput" /> <span class="error"><form:errorspath="MemberModel.userName" /></span><br /><br /><center><input type="submit" value="확인" class="submitBt" /> <inputtype="reset" value="재작성" class="submitBt" /><br /><br /> <a href="<%=request.getContextPath()%>/login.do">로그인페이지로 돌아가기</a></center></fieldset></form></div></body>cs [/WEB-INF/board/list.jsp]
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697<%@ 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 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 href="<%=request.getContextPath()%>/css/board.css"rel="stylesheet" type="text/css" /><script type="text/javascript"src="<%=request.getContextPath()%>/js/jquery-1.7.1.js"></script><script type="text/javascript"><!--function selectedOptionCheck(){$("#type > option[value=<%=request.getParameter("type")%>]").attr("selected", "true");}function moveAction(where) {switch (where) {case 1:location.href = "write.do";break;case 2:location.href = "list.do";break;}}//--></script></head><body onload="selectedOptionCheck()"><div class="wrapper"><div class="navBar"><ul><li><a href="list.do">스프링 게시판</a></li><li><a href="../logout.do">로그아웃</a></li></ul><form action="list.do" method="get"><select id="type" name="type"><option value="subject">제목</option><option value="content">내용</option><option value="writer">작성자</option></select> <input type="text" id="keyword" name="keyword"value="<%if (request.getParameter("keyword") != null) {out.print(request.getParameter("keyword"));} else {out.print("");}%>" /><input type="submit" value="검색" /></form></div><table border="0" class="boardTable"><thead><tr><th>글번호</th><th>제목</th><th>작성자</th><th>댓글수</th><th>조회수</th><th>추천수</th><th>작성일</th></tr></thead><tbody><c:forEach var="board" items="${boardList}"><tr><td class="idx">${board.rnum}</td><td align="left" class="subject"><c:iftest="${board.comment >= 10}"><img src="<%=request.getContextPath()%>/img/hit.jpg" /></c:if> <a href="view.do?idx=${board.idx}">${board.subject}</a></td><td class="writer"><c:choose><c:when test="${board.writerId == userId}"><strong>${board.writer}</strong></c:when><c:otherwise>${board.writer}</c:otherwise></c:choose></td><td class="comment">${board.comment}</td><td class="hitcount">${board.hitcount}</td><td class="recommendcount">${board.recommendcount}</td><td class="writeDate">${board.writeDate}</td></tr></c:forEach></tbody></table><br /> ${pageHtml} <br /><br /> <input type="button" value="목록" class="writeBt"onclick="moveAction(2)" /> <input type="button" value="쓰기"class="writeBt" onclick="moveAction(1)" /></div></body></html>cs [/WEB-INF/board/write.jsp]
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758<%@ 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 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 href="<%=request.getContextPath()%>/css/board.css"rel="stylesheet" type="text/css" /><script type="text/javascript"src="<%=request.getContextPath()%>/js/jquery-1.7.1.js"></script><script type="text/javascript">function writeFormCheck() {if ($("#subject").val() == null || $("#subject").val() == "") {alert("제목을 입력해 주세요!");$("#subject").focus();return false;}if ($("#content").val() == null || $("#content").val() == "") {alert("내용을 입력해 주세요!");$("#content").focus();return false;}return true;}</script></head><body><div class="wrapper"><h3>새 글 쓰기</h3><form action="write.do" method="post"onsubmit="return writeFormCheck()" enctype="multipart/form-data"><table class="boardWrite"><tr><th><label for="subject">제목</label></th><td><input type="text" id="subject" name="subject"class="boardSubject" /> <input type="hidden" id="writer"name="writer" value="${userName}" /> <input type="hidden"id="writerId" name="writerId" value="${userId}" /></td></tr><tr><th><label for="content">내용</label></th><td><textarea id="content" name="content" class="boardContent"></textarea></td></tr><tr><th><label for="file">파일</label></th><td><input type="file" id="file" name="file" /><spanclass="date"> * 임의로 파일명이 변경될 수 있습니다.</span></td></tr></table><br /> <input type="reset" value="재작성" class="writeBt" /> <inputtype="submit" value="확인" class="writeBt" /></form></div></body></html>cs [/WEB-INF/board/view.jsp]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145<%@ 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 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>글 보기: ${board.subject}</title><link href="<%=request.getContextPath()%>/css/board.css"rel="stylesheet" type="text/css" /><script type="text/javascript">function errCodeCheck(){var errCode = <%=request.getParameter("errCode")%>;if(errCode != null || errCode != ""){switch (errCode) {case 1:alert("잘못된 접근 경로입니다!");break;case 2:alert("댓글이 있어 글을 삭제하실 수 없습니다!");break;}}}function commentDelete(commentIdx, linkedArticleNum){if(confirm("선택하신 댓글을 삭제하시겠습니까?")){location.href("commentDelete.do?idx=" + commentIdx + "&linkedArticleNum=" + linkedArticleNum);}}function moveAction(where){switch (where) {case 1:if(confirm("글을 삭제하시겠습니까?")){location.href ="delete.do?idx=${board.idx}";}break;case 2:if(confirm("글을 수정하시겠습니까?")){location.href = "modify.do?idx=${board.idx}";}break;case 3:location.href = "list.do";break;case 4:if(confirm("글을 추천하시겠습니까?")){location.href = "recommend.do?idx=${board.idx}";}break;}}</script></head><body onload="errCodeCheck()"><div class="wrapper"><table class="boardView"><tr><td colspan="4"><h3>${board.subject}</h3></td></tr><tr><th>작성자</th><th>조회수</th><th>추천수</th><th>작성일</th></tr><tr><td>${board.writer}</td><td>${board.hitcount}</td><td>${board.recommendcount}</td><td>${board.writeDate}</td></tr><tr><th colspan="4">내용</th></tr><c:if test="${board.fileName != null }"><tr><td colspan="4" align="left"><span class="date">첨부파일: <ahref="<%=request.getContextPath()%>/files/${board.fileName}"target="_blank">${board.fileName}</a></span></td></tr></c:if><tr><td colspan="4" align="left"><p>${board.content}</p><br /><br /></td></tr></table><table class="commentView"><tr><th colspan="2">댓글</th></tr><c:forEach var="comment" items="${commentList}"><tr><td class="writer"><p>${comment.writer}<c:if test="${comment.writerId == userId}"><br /><a onclick="commentDelete(${comment.idx}, ${board.idx})"><small>댓글삭제</small></a></c:if></p></td><td class="content" align="left"><span class="date">${comment.writeDate}</span><p>${comment.content}</p></td></tr></c:forEach><tr><td class="writer"><strong>댓글 쓰기</strong></td><td class="content"><form action="commentWrite.do" method="post"><input type="hidden" id="writer" name="writer" value="${userName}" /><input type="hidden" id="writerId" name="writerId"value="${userId}" /> <input type="hidden" id="linkedArticleNum"name="linkedArticleNum" value="${board.idx}" /><textarea id="content" name="content" class="commentForm"></textarea><input type="submit" value="확인" class="commentBt" /></form></td></tr></table><br /><c:choose><c:when test="${board.writerId == userId}"><input type="button" value="삭제" class="writeBt"onclick="moveAction(1)" /><input type="button" value="수정" class="writeBt"onclick="moveAction(2)" /><input type="button" value="목록" class="writeBt"onclick="moveAction(3)" /></c:when><c:otherwise><input type="button" value="추천" class="writeBt"onclick="moveAction(4)" /><input type="button" value="목록" class="writeBt"onclick="moveAction(3)" /></c:otherwise></c:choose></div></body></html>cs [/WEB-INF/board/modify.jsp]
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162<%@ 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 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>글 수정: ${board.subject}</title><link href="<%=request.getContextPath()%>/css/board.css"rel="stylesheet" type="text/css" /><script type="text/javascript"src="<%=request.getContextPath()%>/js/jquery-1.7.1.js"></script><script type="text/javascript">function writeFormCheck() {if ($("#subject").val() == null || $("#subject").val() == "") {alert("제목을 입력해 주세요!");$("#subject").focus();return false;}if ($("#content").val() == null || $("#content").val() == "") {alert("내용을 입력해 주세요!");$("#content").focus();return false;}return true;}</script></head><body><div class="wrapper"><h3>새 글 쓰기</h3><form action="modify.do" method="post"onsubmit="return writeFormCheck()" enctype="multipart/form-data"><table class="boardWrite"><tr><th>제목</th><td><input type="text" id="subject" name="subject"class="boardSubject" value="${board.subject}" /> <inputtype="hidden" id="writer" name="writer" value="${userName}" /> <inputtype="hidden" id="writerId" name="writerId" value="${userId}" /><input type="hidden" id="idx" name="idx" value="${board.idx}" /></td></tr><tr><th>내용</th><td><textarea id="content" name="content" class="boardContent">${board.content}</textarea></td></tr><tr><th><label for="file">파일</label></th><td><input type="file" id="newFile" name="newFile" /><p>업로드된 파일: ${board.fileName}</p> <input type="hidden" id="orgFile"name="orgFile" value="${board.fileName}" /></td></tr></table><br /> <input type="reset" value="재작성" class="writeBt" /> <inputtype="submit" value="확인" class="writeBt" /></form></div></body></html>cs 반응형'프로그래밍 > Spring' 카테고리의 다른 글
[Spring] XML을 이용한 DI(Dependency Injection) 설정 (0) 2015.09.23 [Spring] Spring MVC Framework 프로젝트 WAR파일 (0) 2015.09.21 [Spring] 02-2. ViewResolver 설정 (0) 2015.09.15 [Spring] 01-11. ModelAttribute Annotation을 이용한 모델 데이터 처리 (0) 2015.09.15 [Spring] 01-10. 컨트롤러 메서드의 리턴 타입 (0) 2015.09.15