๐กKey Point๐ก
๐@ExceptionHandler
๐Interceptor ํด๋์ค
๐ข๊ธฐ์กด์ USERINFO ํ ์ด๋ธ ์ฌ์ฉ
๐ข์ํธํ ์ฒ๋ฆฌ๋ฅผ ์ํด์ ํ ์ด๋ธ ์ด๊ธฐํ ์์truncate table userinfo;
๐Userinfo.java
โป xyz.itwill10.dto ํจํค์ง์ Userinfo.java ํด๋์ค ์์ฑ
package xyz.itwill10.dto; // import lombok.Data; /* ์ด๋ฆ ๋? ์ ํ -------- -------- ------------- USERID NOT NULL VARCHAR2(100) PASSWORD VARCHAR2(100) NAME VARCHAR2(200) EMAIL VARCHAR2(300) STATUS NUMBER(1) */ @Data public class Userinfo { private String userid; private String password; private String name; private String email; private int status; }
๐UserinfoMapper.xml
โป xyz.itwill10.mapper ํจํค์ง์ UserinfoMapper.xml ํ์ผ ์์ฑ
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="xyz.itwill10.mapper.UserinfoMapper"> <!-- =============================================================================================== --> <insert id="insertUserinfo"> insert into userinfo values(#{userid},#{password},#{name},#{email},#{status}) </insert> <!-- =============================================================================================== --> <update id="updateUserinfo"> update userinfo <set> <if test="password!=null and password!=''"> password=#{password}, </if> <if test="name!=null and name!=''"> name=#{name}, </if> <if test="email!=null and email!=''"> email=#{email}, </if> <if test="status==1 or status==9"> status=#{status} </if> </set> where userid=#{userid} </update> <!-- =============================================================================================== --> <delete id="deleteUserinfo"> delete from userinfo where userid=#{userid} </delete> <!-- =============================================================================================== --> <select id="selectUserinfo" resultType="Userinfo"> select * from userinfo where userid=#{userid} </select> <!-- =============================================================================================== --> <select id="selectUserinfoList" resultType="Userinfo"> select * from userinfo order by userid </select> </mapper>
๐UserinfoMapper.java(์ธํฐํ์ด์ค)
โป xyz.itwill10.mapper ํจํค์ง์ UserinfoMapper.java ์ธํฐํ์ด์ค ํ์ผ ์์ฑ
package xyz.itwill10.mapper; // import java.util.List; import xyz.itwill10.dto.Userinfo; // public interface UserinfoMapper { int insertUserinfo(Userinfo userinfo); int updateUserinfo(Userinfo userinfo); int deleteUserinfo(String userid); Userinfo selectUserinfo(String userid); List<Userinfo> selectUserinfoList(); }
๐UserinfoDAO.java(์ธํฐํ์ด์ค)
โป xyz.itwill10.dao ํจํค์ง์ UserinfoDAO.java ์ธํฐํ์ด์ค ์์ฑ
package xyz.itwill10.dao; // import java.util.List; import xyz.itwill10.dto.Userinfo; // public interface UserinfoDAO { int insertUserinfo(Userinfo userinfo); int updateUserinfo(Userinfo userinfo); int deleteUserinfo(String userid); Userinfo selectUserinfo(String userid); List<Userinfo> selectUserinfoList(); }
๐UserinfoDAOImpl.java
โป xyz.itwill10.dao ํจํค์ง์ UserinfoDAOImpl.java ํด๋์ค ์์ฑ
package xyz.itwill10.dao; // import java.util.List; import org.apache.ibatis.session.SqlSession; import org.springframework.stereotype.Repository; import lombok.RequiredArgsConstructor; import xyz.itwill10.dto.Userinfo; import xyz.itwill10.mapper.UserinfoMapper; // @Repository @RequiredArgsConstructor public class UserinfoDAOImpl implements UserinfoDAO { private final SqlSession sqlSession; // @Override public int insertUserinfo(Userinfo userinfo) { return sqlSession.getMapper(UserinfoMapper.class).insertUserinfo(userinfo); } @Override public int updateUserinfo(Userinfo userinfo) { return sqlSession.getMapper(UserinfoMapper.class).updateUserinfo(userinfo); } @Override public int deleteUserinfo(String userid) { return sqlSession.getMapper(UserinfoMapper.class).deleteUserinfo(userid); } @Override public Userinfo selectUserinfo(String userid) { return sqlSession.getMapper(UserinfoMapper.class).selectUserinfo(userid); } @Override public List<Userinfo> selectUserinfoList() { return sqlSession.getMapper(UserinfoMapper.class).selectUserinfoList(); } }
๐ExistsUserinfoException.java
โป src/main/java ํด๋์ xyz.itwill10.exception ํจํค์ง ์์ฑ
โป xyz.itwill10.exception ํจํค์ง์ ExistsUserinfoException.java ํด๋์ค ์์ฑpackage xyz.itwill10.exception; // import lombok.Getter; import lombok.Setter; import xyz.itwill10.dto.Userinfo; // //ํ์์ ๋ณด์ ๋ํ ๋ฑ๋ก ๋ช ๋ น์ด ์คํ๋ ๋ ์ฌ์ฉ์๋ก๋ถํฐ ์ ๋ ฅ๋ฐ์ ์ ๋ฌ๋ ํ์์ ๋ณด์ ์์ด๋๊ฐ ์ด๋ฏธ ํ์์ ๋ณด์ ์์ด๋๋ก ์กด์ฌํ๋ ๊ฒฝ์ฐ ๋ฐ์๋์ด ์ฒ๋ฆฌํ๊ธฐ ์ํ ์์ธ ํด๋์ค @Getter @Setter public class ExistsUserinfoException extends Exception { private static final long serialVersionUID = 1L; // //์์ธ ์ฒ๋ฆฌ์ ํ์ํ ๊ฐ์ ์ ์ฅํ๊ธฐ ์ํ ํ๋ //โ ์ฌ์ฉ์๋ก๋ถํฐ ์ ๋ ฅ๋์ด ์ ๋ฌ๋ ํ์์ ๋ณด๋ฅผ ์ ์ฅํ๊ธฐ ์ํ ํ๋ private Userinfo userinfo; // public ExistsUserinfoException() {//์์ฑ์ // TODO Auto-generated constructor stub } public ExistsUserinfoException(String message, Userinfo userinfo) { super(message);//๋ถ๋ชจ? this.userinfo=userinfo; } }
๐UserinfoNotFoundException.java
โป xyz.itwill10.exception ํจํค์ง์ UserinfoNotFoundException.java ํด๋์ค ์์ฑ
package xyz.itwill10.exception; // //ํ์์ ๋ณด์ ๋ํ ๋ณ๊ฒฝ,์ญ์ ,๊ฒ์ ๋ช ๋ น์ด ์คํ๋ ๋ ์ฌ์ฉ์๋ก๋ถํฐ ์ ๋ฌ๋ฐ์ ์์ด๋์ ํ์์ ๋ณด๊ฐ ์์ ๊ฒฝ์ฐ ๋ฐ์๋์ด ์ฒ๋ฆฌํ๊ธฐ ์ํ ์์ธ ํด๋์ค public class UserinfoNotFoundException extends Exception { private static final long serialVersionUID = 1L; // public UserinfoNotFoundException() {//์์ฑ์ // TODO Auto-generated constructor stub } public UserinfoNotFoundException(String message) { super(message); } }
๐LoginAuthFailException.java
โป xyz.itwill10.exception ํจํค์ง์ LoginAuthFailException.java ํด๋์ค ์์ฑ
package xyz.itwill10.exception; // import lombok.Getter; import lombok.Setter; // //๋ก๊ทธ์ธ์ ๋ํ ์ธ์ฆ ๋ช ๋ น์ด ์คํ๋ ๋ ์ฌ์ฉ์๋ก๋ถํฐ ์ ๋ฌ๋ฐ์ ์์ด๋์ ๋น๋ฐ๋ฒํธ์ ๋ํ ์ธ์ฆ ์คํจ๋ ๊ฒฝ์ฐ ๋ฐ์๋์ด ์ฒ๋ฆฌํ๊ธฐ ์ํ ์์ธ ํด๋์ค @Getter @Setter public class LoginAuthFailException extends Exception { private static final long serialVersionUID = 1L; // //์์ธ์ฒ๋ฆฌ์ ํ์ํ ๊ฐ์ ์ ์ฅํ๊ธฐ ์ํ ํ๋ //โ ์ฌ์ฉ์๋ก๋ถํฐ ์ ๋ ฅ๋์ด ์ ๋ฌ๋ ์์ด๋๋ฅผ ์ ์ฅํ๊ธฐ ์ํ ํ๋ private String userid; // public LoginAuthFailException() {//์์ฑ์ // TODO Auto-generated constructor stub } public LoginAuthFailException(String message, String userid) { super(message); this.userid=userid; } }
๐UserinfoService.java(์ธํฐํ์ด์ค)
โป xyz.itwill10.service ํจํค์ง์ UserinfoService.java ์ธํฐํ์ด์ค ํ์ผ ์์ฑ
package xyz.itwill10.service; // import java.util.List; import xyz.itwill10.dto.Userinfo; import xyz.itwill10.exception.ExistsUserinfoException; import xyz.itwill10.exception.LoginAuthFailException; import xyz.itwill10.exception.UserinfoNotFoundException; // public interface UserinfoService { void addUserinfo(Userinfo userinfo) throws ExistsUserinfoException; void modifyUserinfo(Userinfo userinfo) throws UserinfoNotFoundException;//ํ์์ ๋ณด ๋ณ๊ฒฝ void removeUserinfo(String userid) throws UserinfoNotFoundException;//ํ์์ ๋ณด ์ญ์ Userinfo getUserinfo(String userid) throws UserinfoNotFoundException;//ํ์์ ๋ณด ๊ฒ์ List<Userinfo> getUserinfoList();//ํ์๋ชฉ๋ก ๊ฒ์ Userinfo loginAuth(Userinfo userinfo) throws LoginAuthFailException; }
๐UserinfoServiceImpl.java
โป xyz.itwill10.service ํจํค์ง์ UserinfoServiceImpl.java ํด๋์ค ์์ฑ
package xyz.itwill10.service; // import java.util.List; import org.mindrot.jbcrypt.BCrypt; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; import xyz.itwill10.dao.UserinfoDAO; import xyz.itwill10.dto.Userinfo; import xyz.itwill10.exception.ExistsUserinfoException; import xyz.itwill10.exception.LoginAuthFailException; import xyz.itwill10.exception.UserinfoNotFoundException; // //์ํธํ ์ฒ๋ฆฌ ๊ธฐ๋ฅ์ ์ฌ์ฉํ๊ธฐ ์ํ ๋ฐฉ๋ฒ //1. jbcrypt ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ๋ก์ ํธ์ ๋น๋ ์ฒ๋ฆฌ - ๋ฉ์ด๋ธ : pom.xml //2. BCrypt.hashpw(String password, String salt) ๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ๋น๋ฐ๋ฒํธ์ ์ํธํ ์ฒ๋ฆฌ //โ ๋งค๊ฐ๋ณ์๋ก ๋ฌธ์์ด๊ณผ ์ฒจ๊ฐ๋ฌผ์ ์ ๋ฌ๋ฐ์ ์ํธํ ์ฒ๋ฆฌ - ์ฒจ๊ฐ๋ฌผ์ ์ํด ๋น๋ฐ๋ฒํธ๊ฐ ๋ค๋ฅด๊ฒ ๋ณํ //โ BCrypt ํด๋์ค : BlowFish ์๊ณ ๋ฆฌ์ฆ์ ๊ธฐ๋ฐ์ผ๋ก ์ค๊ณ๋ ๋จ๋ฐฉํฅ ์ํธํ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ํด๋์ค //โ BCrypt.gensalt(int log_bounds) : ์ฒจ๊ฐ๋ฌผ(Salt - String)์ ๊ธธ์ด๋ฅผ ์ ๋ฌ๋ฐ์ ์ฒจ๊ฐ๋ฌผ์ ์์ฑํ์ฌ ๋ฐํํ๋ ๋ฉ์๋ //โ ๋งค๊ฐ๋ณ์๊ฐ ์๋ ๋ฉ์๋๋ก ํธ์ถํ ๊ฒฝ์ฐ ์ฒจ๊ฐ๋ฌผ์ ๊ธฐ๋ณธ ๊ธธ์ด๋ [10]์ผ๋ก ์๋ ์ค์ //3. BCrypt.checkpw(String plaintext, String hashed)๋ก ์ํธํ๋ ๋น๋ฐ๋ฒํธ๋ฅผ ๋น๊ตํ์ฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํ๋ฐ์ ์ฒ๋ฆฌ //โ ๋งค๊ฐ๋ณ์๋ก ๋น๋ฐ๋ฒํธ์ ์ํธํ๋ ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ฌ๋ฐ์ ๋น๊ตํ์ฌ ๋ค๋ฅธ ๊ฒฝ์ฐ [false]๋ฅผ ๋ฐํํ๊ณ ๊ฐ์ ๊ฒฝ์ฐ [true] ๋ฐํ // //Service ํด๋์ค์ ๋ฉ์๋๋ ๋ฐ์ดํฐ ์ฒ๋ฆฌ์ ๋ฐ์๋๋ ๋ฌธ์ ์ ๋ํ ์ธ์์ ์์ธ ๋ฐ์ //โ ๋ฐ์๋ ์์ธ๋ Controller ํด๋์ค์์ ์์ธ ์ฒ๋ฆฌ๋๋๋ก ์ ๋ฌ @Service @RequiredArgsConstructor public class UserinfoServiceImpl implements UserinfoService { private final UserinfoDAO userinfoDAO; // @Transactional//์์ธ๊ฐ ๋ฐ์๋๋ฉด ์๋์ผ๋ก ๋กค๋ฐฑ์ฒ๋ฆฌ @Override public void addUserinfo(Userinfo userinfo) throws ExistsUserinfoException { //์ ๋ฌ๋ฐ์ ํ์์ ๋ณด์ ์์ด๋๊ฐ ๊ธฐ์กด ํ์์ ๋ณด์ ์์ด๋์ ์ค๋ณต๋ ๊ฒฝ์ฐ if(userinfoDAO.selectUserinfo(userinfo.getUserid())!=null) { //์ฌ์ฉ์ ์ ์ ์์ธ ํด๋์ค๋ก ์ธ์์ ์์ธ ๋ฐ์ //โ ์์ธ๋ฅผ ๋ช ํํ๊ฒ ๊ตฌ๋ถํ๊ณ ์์ธ์ฒ๋ฆฌ์ ํ์๊ฐ์ ์ ์ฅํ์ฌ ์ ๋ฌํ๊ธฐ ์ํ ์ฌ์ฉ์ ์ ์ ์์ธ ํด๋์ค ์์ฑ throw new ExistsUserinfoException("์ด๋ฏธ ์ฌ์ฉ์ค์ธ ์์ด๋๋ฅผ ์ ๋ ฅ ํ์์ต๋๋ค.", userinfo); } //์ ๋ฌ๋ฐ์ ํ์์ ๋ณด์ ๋น๋ฐ๋ฒํธ๋ฅผ ์ํธํ ์ฒ๋ฆฌํ์ฌ ํ๋๊ฐ ์ ์ฅ //โ ์ ๋ฌ๋ฐ์ ํ์์ ๋ณด์ ๋น๋ฐ๋ฒํธ๋ฅผ ์ํธํ ์ฒ๋ฆฌํ์ฌ ํ๋๊ฐ์ผ๋ก ๋ณ๊ฒฝํ๋ ๋ช ๋ น์ Controller ํด๋์ค์ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์์ String hashedPassword=BCrypt.hashpw(userinfo.getPassword(), BCrypt.gensalt()); userinfo.setPassword(hashedPassword); // userinfoDAO.insertUserinfo(userinfo); } // @Transactional @Override public void modifyUserinfo(Userinfo userinfo) throws UserinfoNotFoundException { //์ ๋ฌ๋ฐ์ ํ์์ ๋ณด์ ์์ด๋๋ก ๊ธฐ์กด ํ์์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ๊ฒ์๊ฒฐ๊ณผ๊ฐ ์๋ ๊ฒฝ์ฐ if(userinfoDAO.selectUserinfo(userinfo.getUserid())==null) { throw new UserinfoNotFoundException("์์ด๋์ ํ์์ ๋ณด๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค."); } //์ ๋ฌ๋ฐ์ ํ์์ ๋ณด์ ๋น๋ฐ๋ฒํธ๊ฐ ์กด์ฌํ ๊ฒฝ์ฐ - ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ if(userinfo.getPassword()!=null && !userinfo.getPassword().equals("")) { String hashedPassword=BCrypt.hashpw(userinfo.getPassword(), BCrypt.gensalt()); userinfo.setPassword(hashedPassword); } userinfoDAO.updateUserinfo(userinfo);//๋ณ๊ฒฝ ์ฒ๋ฆฌ } // @Transactional @Override public void removeUserinfo(String userid) throws UserinfoNotFoundException { //์ ๋ฌ๋ฐ์ ์์ด๋๋ก ๊ธฐ์กด ํ์์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ๊ฒ์๊ฒฐ๊ณผ๊ฐ ์๋ ๊ฒฝ์ฐ if(userinfoDAO.selectUserinfo(userid)==null) { throw new UserinfoNotFoundException("์์ด๋์ ํ์์ ๋ณด๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค."); } userinfoDAO.deleteUserinfo(userid); } // @Override public Userinfo getUserinfo(String userid) throws UserinfoNotFoundException { //์ ๋ฌ๋ฐ์ ์์ด๋๋ก ๊ธฐ์กด ํ์์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ๊ฒ์๊ฒฐ๊ณผ๋ฅผ ๋ฐํ๋ฐ์ ์ ์ฅ Userinfo userinfo=userinfoDAO.selectUserinfo(userid); //๊ฒ์๋ ํ์์ ๋ณด๊ฐ ์๋ ๊ฒฝ์ฐ if(userinfo==null) { throw new UserinfoNotFoundException("์์ด๋์ ํ์์ ๋ณด๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค."); } return userinfo; } // @Override public List<Userinfo> getUserinfoList() { return userinfoDAO.selectUserinfoList(); } // //ํ์์ ๋ณด๋ฅผ ์ ๋ฌ๋ฐ์ ์ธ์ฆ ์ฒ๋ฆฌํ๊ธฐ ์ํ ๋ฉ์๋ - ์์ธ๊ฐ ๋ฐ์๋ ๊ฒฝ์ฐ ์ธ์ฆ ์คํจ //โ ์์ธ๊ฐ ๋ฐ์๋์ง ์์ ๊ฒฝ์ฐ ์ธ์ฆ ์ฑ๊ณต์ผ๋ก ๊ฒ์๋ ํ์์ ๋ณด๋ฅผ ๋ฐํ @Override public Userinfo loginAuth(Userinfo userinfo) throws LoginAuthFailException { //์ ๋ฌ๋ฐ์ ํ์์ ๋ณด์ ์์ด๋๋ก ๊ธฐ์กด ํ์์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ๊ฒ์๊ฒฐ๊ณผ๋ฅผ ๋ฐํ๋ฐ์ ์ ์ฅ Userinfo authUserinfo=userinfoDAO.selectUserinfo(userinfo.getUserid()); // //๊ฒ์๋ ํ์์ ๋ณด๊ฐ ์๋ ๊ฒฝ์ฐ - ์์ด๋ ์ธ์ฆ ์คํจ if(authUserinfo==null) { throw new LoginAuthFailException("์์ด๋์ ํ์์ ๋ณด๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค.", userinfo.getUserid()); } // //์ ๋ฌ๋ฐ์ ๋น๋ฐ๋ฒํธ์ ๊ฒ์๋ ํ์์ ๋ณด์ ๋น๋ฐ๋ฒํธ๋ฅผ ๋น๊ตํ์ฌ ๊ฐ์ง ์์ ๊ฒฝ์ฐ - ๋น๋ฐ๋ฒํธ ์ธ์ฆ ์คํจ if(!BCrypt.checkpw(userinfo.getPassword(), authUserinfo.getPassword())) { throw new LoginAuthFailException("์์ด๋๊ฐ ์๊ฑฐ๋ ๋น๋ฐ๋ฒํธ๊ฐ ๋ง์ง ์์ต๋๋ค.", userinfo.getUserid()); } return authUserinfo; } }
๐UserinfoController.java
โป xyz.itwill10.controller ํจํค์ง์ UserinfoController.java ํด๋์ค ์์ฑ
package xyz.itwill10.controller; // import javax.servlet.http.HttpSession; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ExceptionHandler; 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.bind.annotation.RequestParam; import lombok.RequiredArgsConstructor; import xyz.itwill10.dto.Userinfo; import xyz.itwill10.exception.ExistsUserinfoException; import xyz.itwill10.exception.LoginAuthFailException; import xyz.itwill10.exception.UserinfoNotFoundException; import xyz.itwill10.service.UserinfoService; // @Controller @RequestMapping("/userinfo") @RequiredArgsConstructor public class UserinfoController { private final UserinfoService userinfoService; /* //ํ์๋ฑ๋ก์ ์ํด ํ์์ ๋ณด๋ฅผ ์ ๋ ฅ๋ฐ๊ธฐ ์ํ ๋ทฐ์ด๋ฆ์ ๋ฐํํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ //โ ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์ ๋๋ ๊ด๋ฆฌ์๊ฐ ์๋ ์ฌ์ฉ์๊ฐ ํ์ด์ง๋ฅผ ์์ฒญํ ๊ฒฝ์ฐ ์ธ์์ ์์ธ ๋ฐ์ //โ ์์ธ ์ฒ๋ฆฌ ๋ฉ์๋์ ์ํด ์์ธ ์ฒ๋ฆฌ - ์๋ฌ ๋ฉ์ธ์ง๋ฅผ ์ถ๋ ฅํ๋ JSP ๋ฌธ์๋ก ํฌ์๋ ์ด๋ํ์ฌ ์๋ต @RequestMapping(value = "/write", method = RequestMethod.GET) public String write(HttpSession session) throws Exception { //์ธ์ ์ ์ ์ฅ๋ ๊ถํ ๊ด๋ จ ๊ฐ์ฒด๋ฅผ ๋ฐํ๋ฐ์ ์ ์ฅ Userinfo loginUserinfo=(Userinfo)session.getAttribute("loginUserinfo"); if(loginUserinfo==null || loginUserinfo.getStatus()!=9) { throw new Exception("๋น์ ์์ ์ธ ์์ฒญ์ ๋๋ค."); } return "userinfo/user_write"; } */ //ํ์๋ฑ๋ก์ ์ํด ํ์์ ๋ณด๋ฅผ ์ ๋ ฅ๋ฐ๊ธฐ ์ํ ๋ทฐ์ด๋ฆ์ ๋ฐํํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ //โ ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์ ๋๋ ๊ด๋ฆฌ์๊ฐ ์๋ ์ฌ์ฉ์๊ฐ ํ์ด์ง ์์ฒญํ ๊ฒฝ์ฐ ๊ถํ ๊ด๋ จ ์ธํฐ์ ํฐ๋ฅผ ์ด์ฉํ์ฌ ์ฒ๋ฆฌ //โ ๊ถํ ๊ด๋ จ ์ธํฐ์ ํฐ๋ฅผ ์ด์ฉํ ๊ฒฝ์ฐ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์์ ๊ถํ ๊ด๋ จ ๋ช ๋ น ๋ฏธ์์ฑ ๊ฐ๋ฅ @RequestMapping(value = "/write", method = RequestMethod.GET) public String write() { return "userinfo/user_write"; } // /* //ํ์์ ๋ณด๋ฅผ ์ ๋ฌ๋ฐ์ USERINFO ํ ์ด๋ธ์ ์ฝ์ ํ๊ณ ๋ก๊ทธ์ธ ํ์ด์ง๋ฅผ ์์ฒญํ๊ธฐ ์ํ URL ์ฃผ์๋ฅผ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌํ๋ ์์ฒญ์ฒ๋ฆฌ ๋ฉ์๋ //โ UserinfoService ๊ฐ์ฒด์ ๋ฉ์๋ ํธ์ถ์ ์์ธ ๋ฐ์ ๊ฐ๋ฅ(์์ด๋ ์ค๋ณต) - try~catch ๊ตฌ๋ฌธ์ ์ฌ์ฉํ์ฌ ์์ธ ์ฒ๋ฆฌ @RequestMapping(value = "/write", method = RequestMethod.POST) public String write(@ModelAttribute Userinfo userinfo, Model model) { try { userinfoService.addUserinfo(userinfo); } catch (ExistsUserinfoException e) { //ExistsUserinfoException ๊ฐ์ฒด์ ์ ์ฅ๋ ์๋ฌ ๋ฉ์ธ์ง๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅ model.addAttribute("message", e.getMessage()); // //ExistsUserinfoException ๊ฐ์ฒด์ ์ ์ฅ๋ ํ์์ ๋ณด(์ฌ์ฉ์ ์ ๋ ฅ๊ฐ)๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅ model.addAttribute("userinfo", userinfo); //์์ด๋ ์ค๋ณต์ผ๋ก ์์ธ๊ฐ ๋ฐ์๋ ๊ฒฝ์ฐ ํ์์ ๋ณด๋ฅผ ์ ๋ ฅ๋ฐ๊ธฐ ์ํ ๋ทฐ์ด๋ฆ์ ๋ฐํ return "userinfo/user_write"; } return "redirect:/userinfo/login"; } */ //ํ์์ ๋ณด๋ฅผ ์ ๋ฌ๋ฐ์ USERINFO ํ ์ด๋ธ์ ์ฝ์ ํ๊ณ ๋ก๊ทธ์ธ ํ์ด์ง๋ฅผ ์์ฒญํ๊ธฐ ์ํ URL ์ฃผ์๋ฅผ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌํ๋ ์์ฒญ์ฒ๋ฆฌ ๋ฉ์๋ //โ UserinfoService ๊ฐ์ฒด์ ๋ฉ์๋ ํธ์ถ์ ์์ธ ๋ฐ์ ๊ฐ๋ฅ - Front Controller์๊ฒ ์์ธ ์ ๋ฌ //โ Front Controller๋ ์ ๋ฌ๋ฐ์ ์์ธ๋ก ์ธํด 500 ์๋ฌ์ฝ๋ ๋ฐ์ํ์ฌ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌ //โ Front Controller๋ ํด๋น ์์ธ์ ๋ํ ExceptionHandler ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ๋ฉ์๋๊ฐ ์์ฑ๋ ๊ฒฝ์ฐ ExceptionHandler ๊ธฐ๋ฅ์ ๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ์์ธ ์ฒ๋ฆฌ ๊ฐ๋ฅ @RequestMapping(value = "/write", method = RequestMethod.POST) public String write(@ModelAttribute Userinfo userinfo) throws ExistsUserinfoException { userinfoService.addUserinfo(userinfo); return "redirect:/userinfo/login"; } // //๋ก๊ทธ์ธ์ ์ํด ์ธ์ฆ์ ๋ณด๋ฅผ ์ ๋ ฅ๋ฐ๊ธฐ ์ํ ๋ทฐ์ด๋ฆ์ ๋ฐํํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ @RequestMapping(value = "/login", method = RequestMethod.GET) public String login() throws Exception { return "userinfo/user_login"; } // //์ธ์ฆ์ ๋ณด๋ฅผ ์ ๋ฌ๋ฐ์ ๋ก๊ทธ์ธ ์ฒ๋ฆฌ ํ ํ์ ๋ฉ์ธ์ง๋ฅผ ์ถ๋ ฅํ๊ธฐ ์ํ ๋ทฐ์ด๋ฆ์ ๋ฐํํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ @RequestMapping(value = "/login", method = RequestMethod.POST) public String login(@ModelAttribute Userinfo userinfo, HttpSession session) throws LoginAuthFailException { //์ธ์ฆ ์คํจ์ LoginAuthFailException ๋ฐ์ํ๊ณ ์ธ์ฆ ์ฑ๊ณต์ ๊ฒ์๋ ํ์์ ๋ณด ๋ฐํ๋ฐ์ ์ ์ฅ Userinfo authUserinfo=userinfoService.loginAuth(userinfo); // //์ธ์ ์ ๊ถํ ๊ด๋ จ ์ ๋ณด๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅ session.setAttribute("loginUserinfo", authUserinfo); // return "userinfo/user_login"; } // //๋ก๊ทธ์์ ์ฒ๋ฆฌ ํ ๋ก๊ทธ์ธ ํ์ด์ง๋ฅผ ์์ฒญํ๊ธฐ ์ํ URL ์ฃผ์๋ฅผ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ @RequestMapping("/logout") public String login(HttpSession session) { //session.removeAttribute("loginUserinfo"); session.invalidate(); // return "redirect:/userinfo/login"; } /* //USERINFO ํ ์ด๋ธ์ ์ ์ฅ๋ ๋ชจ๋ ํ์์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅํ์ฌ ํ์๋ชฉ๋ก์ ์ถ๋ ฅํ๋ ๋ทฐ์ด๋ฆ์ ๋ฐํํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ //โ ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์๊ฐ ํ์ด์ง๋ฅผ ์์ฒญํ ๊ฒฝ์ฐ ์ธ์์ ์์ธ ๋ฐ์ - ์์ธ ์ฒ๋ฆฌ ๋ฉ์๋์ ์ํด ์์ธ ์ฒ๋ฆฌ @RequestMapping("/list") public String list(Model model, HttpSession session) throws Exception { Userinfo loginUserinfo=(Userinfo)session.getAttribute("loginUserinfo"); if(loginUserinfo==null) {//๋น๋ก๊ทธ์ธ ์ฌ์ฉ์๊ฐ ํ์ด์ง๋ฅผ ์์ฒญํ ๊ฒฝ์ฐ throw new Exception("๋น์ ์์ ์ธ ์์ฒญ์ ๋๋ค.");//์ธ์์ ์์ธ ๋ฐ์ } // model.addAttribute("userinfoList", userinfoService.getUserinfoList()); // return "userinfo/user_list"; } */ //USERINFO ํ ์ด๋ธ์ ์ ์ฅ๋ ๋ชจ๋ ํ์์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅํ์ฌ ํ์๋ชฉ๋ก์ ์ถ๋ ฅํ๋ ๋ทฐ์ด๋ฆ์ ๋ฐํํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ //โ ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์๊ฐ ํ์ด์ง๋ฅผ ์์ฒญํ ๊ฒฝ์ฐ ๊ถํ ๊ด๋ จ ์ธํฐ์ ํฐ๋ฅผ ์ด์ฉํ์ฌ ์ฒ๋ฆฌ @RequestMapping("/list") public String list(Model model) { model.addAttribute("userinfoList", userinfoService.getUserinfoList()); return "userinfo/user_list"; } // //์์ด๋๋ฅผ ์ ๋ฌ๋ฐ์ USERINFO ํ ์ด๋ธ์ ์ ์ฅ๋ ํด๋น ์์ด๋์ ํ์์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅํ์ฌ ํ์์ ๋ณด๋ฅผ ์ถ๋ ฅํ๋ ๋ทฐ์ด๋ฆ์ ๋ฐํํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ //โ ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์๊ฐ ํ์ด์ง๋ฅผ ์์ฒญํ ๊ฒฝ์ฐ ๊ถํ ๊ด๋ จ ์ธํฐ์ ํฐ๋ฅผ ์ด์ฉํ์ฌ ์ฒ๋ฆฌ @RequestMapping("/view") public String view(@RequestParam String userid, Model model) throws UserinfoNotFoundException { model.addAttribute("userinfo", userinfoService.getUserinfo(userid)); return "userinfo/user_view"; } // //์์ด๋๋ฅผ ์ ๋ฌ๋ฐ์ USERINFO ํ ์ด๋ธ์ ์ ์ฅ๋ ํด๋น ์์ด๋์ ํ์์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ์์ฑ๊ฐ์ผ๋ก ์ ์ฅํ์ฌ ๋ณ๊ฒฝํ ํ์์ ๋ณด๋ฅผ ์ ๋ ฅ๋ฐ๊ธฐ ์ํ ๋ทฐ์ด๋ฆ์ ๋ฐํํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ //โ ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์ ๋๋ ๊ด๋ฆฌ์๊ฐ ์๋ ์ฌ์ฉ์๊ฐ ํ์ด์ง ์์ฒญํ ๊ฒฝ์ฐ ๊ถํ ๊ด๋ จ ์ธํฐ์ ํฐ๋ฅผ ์ด์ฉํ์ฌ ์ฒ๋ฆฌ @RequestMapping(value = "/modify", method = RequestMethod.GET) public String modify(@RequestParam String userid, Model model) throws UserinfoNotFoundException { model.addAttribute("userinfo", userinfoService.getUserinfo(userid)); return "userinfo/user_modify"; } // //ํ์์ ๋ณด๋ฅผ ์ ๋ฌ๋ฐ์ USERINFO ํ ์ด๋ธ์ ์ ์ฅ๋ ํ์์ ๋ณด๋ฅผ ๋ณ๊ฒฝํ๊ณ ํ์์ ๋ณด๋ฅผ ์ถ๋ ฅํ๋ ํ์ด์ง๋ฅผ ์์ฒญํ๊ธฐ ์ํ URL ์ฃผ์๋ฅผ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ //โ ๋ณ๊ฒฝ ์ฒ๋ฆฌ ํ๊ธฐ ์ํ ์ฌ์ฉ์๊ฐ ๋ก๊ทธ์ธ ์ฌ์ฉ์์ธ ๊ฒฝ์ฐ ์ธ์ ์ ์ ์ฅ๋ ๊ถํ ๊ด๋ จ ์ ๋ณด ๋ณ๊ฒฝ @RequestMapping(value="/modify", method = RequestMethod.POST) public String modify(@ModelAttribute Userinfo userinfo, HttpSession session) throws UserinfoNotFoundException { userinfoService.modifyUserinfo(userinfo); // Userinfo loginUserinfo=(Userinfo)session.getAttribute("loginUserinfo"); //๋ณ๊ฒฝ ์ฒ๋ฆฌ๋ ์ฌ์ฉ์๊ฐ ๋ก๊ทธ์ธ ์ฌ์ฉ์์ธ ๊ฒฝ์ฐ if(loginUserinfo.getUserid().equals(userinfo.getUserid())) { session.setAttribute("loginUserinfo", userinfoService.getUserinfo(userinfo.getUserid())); } // return "redirect:/userinfo/view?userid="+userinfo.getUserid(); } // //์์ด๋๋ฅผ ์ ๋ฌ๋ฐ์ USERINFO ํ ์ด๋ธ์ ์ ์ฅ๋ ํด๋น ์์ด๋์ ํ์์ ๋ณด๋ฅผ ์ญ์ ํ๊ณ ํ์๋ชฉ๋ก์ ์ถ๋ ฅํ๋ ํ์ด์ง๋ฅผ ์์ฒญํ๊ธฐ ์ํ URL ์ฃผ์๋ฅผ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌํ๋ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ //โ ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์ ๋๋ ๊ด๋ฆฌ์๊ฐ ์๋ ์ฌ์ฉ์๊ฐ ํ์ด์ง ์์ฒญํ ๊ฒฝ์ฐ ๊ถํ ๊ด๋ จ ์ธํฐ์ ํฐ๋ฅผ ์ด์ฉํ์ฌ ์ฒ๋ฆฌ @RequestMapping("/remove") public String remove(@RequestParam String userid, HttpSession session) throws UserinfoNotFoundException { userinfoService.removeUserinfo(userid); // Userinfo loginUserinfo=(Userinfo)session.getAttribute("loginUserinfo"); //๋ก๊ทธ์ธ ์ฌ์ฉ์๊ฐ ์ญ์ ๋ ๊ฒฝ์ฐ if(loginUserinfo.getUserid().equals(userid)) { return "redirect:/userinfo/logout"; } // return "redirect:/userinfo/list"; } // //๋ด๊บผ๋ง ์ฒ๋ฆฌ //@ExceptionHandler : Controller ํด๋์ค์ ๋ฉ์๋์ ์์ธ ์ฒ๋ฆฌ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋๋ก ์ค์ ํ๋ ์ด๋ ธํ ์ด์ //โ Controller ํด๋์ค์ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์์ ์์ธ๊ฐ ๋ฐ์๋์ด Front Controller์๊ฒ ์ ๋ฌ๋ ๊ฒฝ์ฐ ์์ธ ๊ด๋ จ ๊ฐ์ฒด๋ฅผ ์ ๊ณต๋ฐ์ ์์ธ ์ฒ๋ฆฌํ๊ธฐ ์ํ ๋ฉ์๋ //value ์์ฑ : ์์ธ ์ฒ๋ฆฌํ๊ธฐ ์ํ ํด๋์ค(Class ๊ฐ์ฒด)๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ค์ //โ ๋ค๋ฅธ ์์ฑ์ด ์๋ ๊ฒฝ์ฐ ์์ฑ๊ฐ๋ง ์ค์ ๊ฐ๋ฅ //์์ธ ์ฒ๋ฆฌ ๋ฉ์๋์์ ์์ธ ์ฒ๋ฆฌ๋ฅผ ์ํด ํ์ํ ๊ฐ์ฒด๋ฅผ ๋งค๊ฐ๋ณ์๋ก ์ ๋ฌ๋ฐ์ ์ฌ์ฉ ๊ฐ๋ฅํ๋ฉฐ ๋ทฐ์ด๋ฆ์ ๋ฐํํด JSP ๋ฌธ์๋ก ์๋ต ์ฒ๋ฆฌ ๊ฐ๋ฅ - ๋ฆฌ๋ค์ด๋ ํธ ์ด๋ ๊ฐ๋ฅ @ExceptionHandler(value = ExistsUserinfoException.class) public String userinfoExceptionHandler(ExistsUserinfoException exception, Model model) { model.addAttribute("message", exception.getMessage()); model.addAttribute("userinfo",exception.getUserinfo()); return "userinfo/user_write"; } // @ExceptionHandler(LoginAuthFailException.class) public String userinfoExceptionHandler(LoginAuthFailException exception, Model model) { model.addAttribute("message", exception.getMessage()); model.addAttribute("userid",exception.getUserid()); return "userinfo/user_login"; } // @ExceptionHandler(UserinfoNotFoundException.class) public String userinfoExceptionHandler(UserinfoNotFoundException exception) { return "userinfo/user_error"; } // /* @ExceptionHandler(Exception.class) public String userinfoExceptionHandler() { return "userinfo/user_error"; } */ }๐ข@ControllerAdvice
๐ExceptionController.java
โป xyz.itwill10.controller ํจํค์ง์ ExceptionController.java ํด๋์ค ์์ฑ
package xyz.itwill10.controller; // import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; // //@ControllerAdvice : ์์ธ ์ฒ๋ฆฌ ๋ฉ์๋๋ง ์์ฑ๋ Controller ํด๋์ค๋ฅผ Spring Bean์ผ๋ก ๋ฑ๋กํ๊ธฐ ์ํ ์ด๋ ธํ ์ด์ //โ ๋ชจ๋ Controller ํด๋์ค์ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์์ ๋ฐ์๋์ด ์ ๋ฌ๋ ์์ธ๋ฅผ ์ ๊ณต๋ฐ์ ์ฒ๋ฆฌ @ControllerAdvice public class ExceptionController { private static final Logger logger=LoggerFactory.getLogger(ExceptionController.class); // @ExceptionHandler(value = Exception.class) public String userinfoExceptionHandler(Exception exception) { exception.printStackTrace(); logger.error(exception.getMessage()); return "userinfo/user_error"; } }
๐user_write.jsp
โป WEB-INF/views/userinfo ํด๋์ user_write.jsp ์์ฑ
<%@ 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> <title>SPRING</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel=stylesheet href="<c:url value="/css/user.css"/>" type="text/css"> <script language="JavaScript"> function userCreate() { if ( f.userid.value == "" ) { alert("์์ด๋๋ฅผ ์ ๋ ฅํ์ญ์์."); f.userid.focus(); return; } if ( f.password.value == "" ) { alert("๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅํ์ญ์์."); f.password.focus(); return; } if ( f.name.value == "" ) { alert("์ด๋ฆ์ ์ ๋ ฅํ์ญ์์."); f.name.focus(); return; } // f.action = "<c:url value="/userinfo/write"/>"; f.submit(); } </script> </head> <body bgcolor=#FFFFFF text=#000000 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0> <br> <table width=780 border=0 cellpadding=0 cellspacing=0> <tr> <td width="20"></td> <td style="color: red;">${message }</td> </tr> <tr> <td width="20"></td> <td> <table width=590 border=0 cellpadding=0 cellspacing=0> <tr> <td bgcolor="f4f4f4" height="22"> <b>ํ์๊ด๋ฆฌ - ํ์๋ฑ๋ก</b></td> </tr> </table> <br> <form name="f" method="post"> <table border="0" cellpadding="0" cellspacing="1" width="590" bgcolor="BBBBBB"> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">์์ด๋</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <input type="text" style="width:150" name="userid" value="${userinfo.userid }"> </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">๋น๋ฐ๋ฒํธ</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <input type="password" style="width:150" name="password" value="${userinfo.password }"> </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">์ด๋ฆ</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <input type="text" style="width:240" name="name" value="${userinfo.name }"> </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">์ด๋ฉ์ผ</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <input type="text" style="width:240" name="email" value="${userinfo.email }"> </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">ํ์๋ฑ๊ธ</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <select name="status"> <option value="1" <c:if test="${userinfo.status == 1 }">selected</c:if>>์ผ๋ฐํ์</option> <option value="9" <c:if test="${userinfo.status == 9 }">selected</c:if>>๊ด๋ฆฌ์</option> </select> </td> </tr> </table> </form> <br> <table width=590 border=0 cellpadding=0 cellspacing=0> <tr> <td align=center> <input type="button" value="ํ์๋ฑ๋ก" onClick="userCreate();"> <input type="button" value="๋ก๊ทธ์ธ"token tag"><c:url value="/userinfo/login"/>';"> </td> </tr> </table> </td> </tr> </table> </body> </html>
๐user_error.jsp
โป WEB-INF/views/userinfo ํด๋์ user_error.jsp ์์ฑ
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>SPRING</title> <style type="text/css"> body { text-align: center; } .message { color: red; font-size: 1.5em; } </style> </head> <body> <h1>์๋ฌํ์ด์ง</h1> <hr> <p class="message">ํ๋ก๊ทธ๋จ ์คํ์ ์๊ธฐ์น ๋ชปํ ์ค๋ฅ๊ฐ ๋ฐ์ ํ์๊ฑฐ๋ ๋น์ ์์ ๋ฐฉ๋ฒ์ผ๋ก ํ๋ก๊ทธ๋จ์ ์์ฒญํ์ฌ ์ค๋ฅ๊ฐ ๋ฐ์ ํ์์ต๋๋ค.</p> <button type="button"token tag"><c:url value="/userinfo/login"/>';">๋ก๊ทธ์ธ ํ์ด์ง ์ด๋</button> </body> </html>
๐user_login.jsp
โป WEB-INF/views/userinfo ํด๋์ user_login.jsp ์์ฑ
<%@ 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> <title>SPRING</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel=stylesheet href="<c:url value="/css/user.css"/>" type="text/css"> <script language="JavaScript"> function userLogin() { if ( f.userid.value == "" ) { alert("์์ด๋๋ฅผ ์ ๋ ฅํ์ญ์์."); f.userid.focus(); return; } if ( f.password.value == "" ) { alert("๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅํ์ญ์์."); f.password.focus(); return; } // f.action = "<c:url value="/userinfo/login"/>"; f.submit(); } </script> </head> <body bgcolor=#FFFFFF text=#000000 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0> <br> <table width=780 border=0 cellpadding=0 cellspacing=0> <tr> <td width="20"></td> <td style="color: red;">${message }</td> </tr> <tr> <td width="20"></td> <td> <!--contents--> <table width=590 border=0 cellpadding=0 cellspacing=0> <tr> <td bgcolor="f4f4f4" height="22"> <b>ํ์๊ด๋ฆฌ - ๋ก๊ทธ์ธ</b></td> </tr> </table> <br> <c:choose> <c:when test="${empty(loginUserinfo) }"><%-- ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์์ธ ๊ฒฝ์ฐ --%> <!-- login Form --> <form name="f" method="post"> <table border="0" cellpadding="0" cellspacing="1" width="590" bgcolor="BBBBBB"> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">์ฌ์ฉ์ ์์ด๋</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <input type="text" style="width:150" name="userid" value="${userid }"> </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">๋น๋ฐ๋ฒํธ</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <input type="password" style="width:150" name="password"> </td> </tr> </table> </form> <br> <table width=590 border=0 cellpadding=0 cellspacing=0> <tr> <td align=center> <input type="button" value="๋ก๊ทธ์ธ" onClick="userLogin();"> </td> </tr> </table> </c:when> <c:otherwise><%-- ๋ก๊ทธ์ธ ์ฌ์ฉ์์ธ ๊ฒฝ์ฐ --%> <table border="0" cellpadding="0" cellspacing="1" width="590" bgcolor="BBBBBB"> <tr> <td align=center bgcolor="E6ECDE" height="22"> ${loginUserinfo.name }๋, ํ์ํฉ๋๋ค. </td> </tr> </table> <br> <table width=590 border=0 cellpadding=0 cellspacing=0> <tr> <td align=center> <button type="button"token tag"><c:url value="/userinfo/list"/>';">ํ์๋ชฉ๋ก</button> <button type="button"token tag"><c:url value="/userinfo/logout"/>';">๋ก๊ทธ์์</button> <c:if test="${loginUserinfo.status == 9 }"> <button type="button"token tag"><c:url value="/userinfo/write"/>';">ํ์๋ฑ๋ก</button> </c:if> </td> </tr> </table> </c:otherwise> </c:choose> </td> </tr> </table> </body> </html>
๐user_list.jsp
โป WEB-INF/views/userinfo ํด๋์ user_list.jsp ์์ฑ
<%@ 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> <title>SPRING</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel=stylesheet href="<c:url value="/css/user.css"/>" type="text/css"> </head> <body bgcolor=#FFFFFF text=#000000 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0> <br> <table width=780 border=0 cellpadding=0 cellspacing=0> <tr> <td width="20"></td> <td> <table width=590 border=0 cellpadding=0 cellspacing=0> <tr> <td bgcolor="f4f4f4" height="22"> <b>ํ์๊ด๋ฆฌ - ํ์๋ชฉ๋ก</b></td> </tr> </table> <br> <table border="0" cellpadding="0" cellspacing="1" width="590" bgcolor="BBBBBB"> <tr> <td width=190 align=center bgcolor="E6ECDE" height="22">์์ด๋</td> <td width=200 align=center bgcolor="E6ECDE">์ด๋ฆ</td> <td width=200 align=center bgcolor="E6ECDE">์ด๋ฉ์ผ</td> </tr> <c:forEach var="userinfo" items="${userinfoList }"> <tr> <td width=190 align=center bgcolor="ffffff" height="20"> ${userinfo.userid } </td> <td width=200 align=center bgcolor="ffffff"> <a href="<c:url value="/userinfo/view"/>?userid=${userinfo.userid }" class="user"> ${userinfo.name } </a> </td> <td width=200 align=center bgcolor="ffffff"> ${userinfo.email } </td> </tr> </c:forEach> </table> <br> <table border="0" cellpadding="0" cellspacing="1" width="590"> <tr> <td align="right"> <c:if test="${loginUserinfo.status == 9 }"> <input type="button" value="ํ์๋ฑ๋ก"token tag"><c:url value="/userinfo/write"/>';"/> </c:if> <input type="button" value="๋ก๊ทธ์์"token tag"><c:url value="/userinfo/logout"/>';"/> </td> </tr> </table> </td> </tr> </table> </body> </html>
๐user_view.jsp
โป WEB-INF/views/userinfo ํด๋์ user_view.jsp ์์ฑ
<%@ 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> <title>SPRING</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel=stylesheet href="<c:url value="/css/user.css"/>" type="text/css"> <script language="JavaScript"> function userRemove(userid) { if (confirm("์ ๋ง๋ก ์ญ์ ํ์๊ฒ ์ต๋๊น?") ) { location.href='<c:url value="/userinfo/remove"/>?userid='+userid; } } </script> </head> <body bgcolor=#FFFFFF text=#000000 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0> <br> <table width=780 border=0 cellpadding=0 cellspacing=0> <tr> <td width="20"></td> <td> <table width=590 border=0 cellpadding=0 cellspacing=0> <tr> <td bgcolor="f4f4f4" height="22"> <b>ํ์๊ด๋ฆฌ - ํ์์ ๋ณด</b></td> </tr> </table> <br> <table border="0" cellpadding="0" cellspacing="1" width="590" bgcolor="BBBBBB"> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">์์ด๋</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> ${userinfo.userid } </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">์ด๋ฆ</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> ${userinfo.name } </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">์ด๋ฉ์ผ</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> ${userinfo.email } </td> </tr> </table> <br> <table width=590 border=0 cellpadding=0 cellspacing=0> <tr> <td align=center> <c:if test="${loginUserinfo.status == 9 }"> <input type="button" value="์์ "token tag"><c:url value="/userinfo/modify"/>?userid=${userinfo.userid}';"> <input type="button" value="์ญ์ " onClick="userRemove('${userinfo.userid}');"> </c:if> <input type="button" value="๋ชฉ๋ก"token tag"><c:url value="/userinfo/list"/>';"> </td> </tr> </table> </td> </tr> </table> </body> </html>
๐user_modify.jsp
โป WEB-INF/views/userinfo ํด๋์ user_modify.jsp ์์ฑ
<%@ 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> <title>SPRING</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel=stylesheet href="<c:url value="/css/user.css"/>" type="text/css"> <script language="JavaScript"> function userModify() { if ( f.name.value == "" ) { alert("์ด๋ฆ์ ์ ๋ ฅํ์ญ์์."); f.name.focus(); return false; } f.action = "<c:url value="/userinfo/modify"/>"; f.submit(); } </script> </head> <body bgcolor=#FFFFFF text=#000000 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0> <br> <table width=780 border=0 cellpadding=0 cellspacing=0> <tr> <td width="20"></td> <td> <table width=590 border=0 cellpadding=0 cellspacing=0> <tr> <td bgcolor="f4f4f4" height="22"> <b>ํ์๊ด๋ฆฌ - ํ์์ ๋ณด์์ </b></td> </tr> </table> <br> <form name="f" method="post"> <input type="hidden" name="userid" value="${userinfo.userid }"> <table border="0" cellpadding="0" cellspacing="1" width="590" bgcolor="BBBBBB"> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">์์ด๋</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> ${userinfo.userid } </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">๋น๋ฐ๋ฒํธ</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <input type="password" style="width:150" name="password"> <span style="color: red;">** ๋น๋ฐ๋ฒํธ๋ฅผ ๋ณ๊ฒฝํ์ง ์์ ๊ฒฝ์ฐ ์ ๋ ฅํ์ง ๋ง์ธ์. **</span> </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">์ด๋ฆ</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <input type="text" style="width:240" name="name" value="${userinfo.name }"> </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">์ด๋ฉ์ผ ์ฃผ์</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <input type="text" style="width:240" name="email" value="${userinfo.email }"> </td> </tr> <tr> <td width=100 align=center bgcolor="E6ECDE" height="22">ํ์๋ฑ๊ธ</td> <td width=490 bgcolor="ffffff" style="padding-left:10px;"> <select name="status"> <option value="1" <c:if test="${userinfo.status == 1 }">selected</c:if>>์ผ๋ฐํ์</option> <option value="9" <c:if test="${userinfo.status == 9 }">selected</c:if>>๊ด๋ฆฌ์</option> </select> </td> </tr> </table> </form> <br> <table width=590 border=0 cellpadding=0 cellspacing=0> <tr> <td align=center> <input type="button" value="์์ " onClick="userModify();"> <input type="button" value="๋ชฉ๋ก"token tag"><c:url value="/userinfo/list"/>';"> </td> </tr> </table> </td> </tr> </table> </body> </html>
โ jbcrypt ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ๋ก์ ํธ์ ๋น๋ ์ฒ๋ฆฌ - ๋ฉ์ด๋ธ : pom.xml
๐pom.xml
<!-- https://mvnrepository.com/artifact/org.mindrot/jbcrypt --> <!-- โ ์ํธํ ์ฒ๋ฆฌ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ --> <dependency> <groupId>org.mindrot</groupId> <artifactId>jbcrypt</artifactId> <version>0.4</version> </dependency>
โกBCrypt.hashpw(String password, String salt) ๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ๋น๋ฐ๋ฒํธ์ ์ํธํ ์ฒ๋ฆฌ
โ ๋งค๊ฐ๋ณ์๋ก ๋ฌธ์์ด๊ณผ ์ฒจ๊ฐ๋ฌผ์ ์ ๋ฌ๋ฐ์ ์ํธํ ์ฒ๋ฆฌ - ์ฒจ๊ฐ๋ฌผ์ ์ํด ๋น๋ฐ๋ฒํธ๊ฐ ๋ค๋ฅด๊ฒ ๋ณํ
โ BCrypt ํด๋์ค : BlowFish ์๊ณ ๋ฆฌ์ฆ์ ๊ธฐ๋ฐ์ผ๋ก ์ค๊ณ๋ ๋จ๋ฐฉํฅ ์ํธํ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ํด๋์ค
โ BCrypt.gensalt(int log_bounds) : ์ฒจ๊ฐ๋ฌผ(Salt - String)์ ๊ธธ์ด๋ฅผ ์ ๋ฌ๋ฐ์ ์ฒจ๊ฐ๋ฌผ์ ์์ฑํ์ฌ ๋ฐํํ๋ ๋ฉ์๋
โ ๋งค๊ฐ๋ณ์๊ฐ ์๋ ๋ฉ์๋๋ก ํธ์ถํ ๊ฒฝ์ฐ ์ฒจ๊ฐ๋ฌผ์ ๊ธฐ๋ณธ ๊ธธ์ด๋ [10]์ผ๋ก ์๋ ์ค์
โขBCrypt.checkpw(String plaintext, String hashed)๋ก ์ํธํ๋ ๋น๋ฐ๋ฒํธ๋ฅผ ๋น๊ตํ์ฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํ๋ฐ์ ์ฒ๋ฆฌ
โ ๋งค๊ฐ๋ณ์๋ก ๋น๋ฐ๋ฒํธ์ ์ํธํ๋ ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ฌ๋ฐ์ ๋น๊ตํ์ฌ ๋ค๋ฅธ ๊ฒฝ์ฐ [false]๋ฅผ ๋ฐํํ๊ณ ๊ฐ์ ๊ฒฝ์ฐ [true] ๋ฐํ
โป src/main/java ํด๋์ xyz.itwill10.util ํจํค์ง ์์ฑ
๐ข๊ด๋ฆฌ์ ๊ด๋ จ ๊ถํ ์ฒ๋ฆฌ๋ฅผ ์ํด ์์ฑ๋ Interceptor ํด๋์ค
๐AdminAuthInterceptor.java
โป xyz.itwill10.util ํจํค์ง์ AdminAuthInterceptor.java ํด๋์ค ์์ฑ
package xyz.itwill10.util; // import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; import xyz.itwill10.dto.Userinfo; // //Interceptor ํด๋์ค : Front Controller์ ์ํด ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋๊ฐ ํธ์ถ๋์ด ์คํ๋๊ธฐ ์ ๋๋ ํ์ ์ฝ์ ๋์ด ์คํ๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ์ ๊ณตํ๋ ํด๋์ค //โ Interceptor ํด๋์ค๋ ๋ฐ๋์ HandlerInterceptor ์ธํฐํ์ด์ค๋ฅผ ์์๋ฐ์ ์์ฑ - ํ์ํ ๋ฉ์๋๋ง ์ค๋ฒ๋ผ์ด๋ ์ ์ธํด์ ์์ฑ //โ Spring Bean Configuration File(servlet-context.xml)์ Spring Bean์ผ๋ก ๋ฑ๋กํ๊ณ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ ํธ์ถ ์ ํ์ ์ธํฐ์ ํฐ๊ฐ ๋์๋ ์ ์๋๋ก ํ๊ฒฝ ์ค์ // //๊ด๋ฆฌ์ ๊ด๋ จ ๊ถํ ์ฒ๋ฆฌ๋ฅผ ์ํด ์์ฑ๋ Interceptor ํด๋์ค //โ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ช ๋ น ์คํ ์ ์ ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์์ด๊ฑฐ๋ ๊ด๋ฆฌ์๊ฐ ์๋ ์ฌ์ฉ์๊ฐ ํ์ด์ง๋ฅผ ์์ฒญํ ๊ฒฝ์ฐ ์๋ฌ ๋ฉ์ธ์ง๋ฅผ ์ถ๋ ฅํ๋ ํ์ด์ง์ URL ์ฃผ์๋ฅผ ์ ๋ฌํ๋ ๊ธฐ๋ฅ ์ ๊ณต public class AdminAuthInterceptor implements HandlerInterceptor { //preHandle : ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ช ๋ น์ด ์คํ๋๊ธฐ ์ ์ ์คํ๋ ๋ช ๋ น์ ์์ฑํ๋ ๋ฉ์๋ //โ false ๋ฐํ : ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ช ๋ น ๋ฏธ์คํ //โ true ๋ฐํ : ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ช ๋ น ์คํ //โ ๊ถํ ๊ด๋ จ ๋ช ๋ น์ ์์ฑํ๊ธฐ ์ํ ๋ฉ์๋ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HttpSession session=request.getSession();//์ธ์ ๊ฐ์ฒด ๋ฐํ // Userinfo loginUserinfo=(Userinfo)session.getAttribute("loginUserinfo"); // //๋น๋ก๊ทธ์ธ ์ฌ์ฉ์์ด๊ฑฐ๋ ๊ด๋ฆฌ์๊ฐ ์๋ ์ฌ์ฉ์์ธ ๊ฒฝ์ฐ if(loginUserinfo==null || loginUserinfo.getStatus()!=9) { //๋ฐฉ๋ฒ1 //request.getRequestDispatcher("userinfo/user_error.jsp").forward(request, response); //return false;//๊ถํ์ด ์๋ ๊ฒฝ์ฐ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ ๋ฏธํธ์ถ // //๋ฐฉ๋ฒ2 throw new Exception("๋น์ ์์ ์ธ ์์ฒญ์ ๋๋ค.");//์ธ์์ ์์ธ ๋ฐ์ - ์์ธ ์ฒ๋ฆฌ ๋ฉ์๋๋ก ์์ธ ์ฒ๋ฆฌ } return true;//๊ถํ์ด ์๋ ๊ฒฝ์ฐ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋ ํธ์ถ } // //postHandle : ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ช ๋ น์ด ์คํ๋๊ณ ๋ทฐ๊ฐ ์์ฑ๋๊ธฐ ์ ์ ์คํ๋ ๋ช ๋ น์ ์์ฑํ๋ ๋ฉ์๋ //โ ModelAndView ๊ฐ์ฒด๋ฅผ ์ ๊ณต๋ฐ์ ViewName ๋๋ Model ๊ฐ์ฒด์ ์์ฑ๊ฐ ๋ณ๊ฒฝํ ๊ฒฝ์ฐ ์ฌ์ฉ @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { // TODO Auto-generated method stub HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); } // //afterCompletion : ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ช ๋ น์ด ์คํ๋๊ณ ๋ทฐ์์ ์ต์ข ๊ฒฐ๊ณผ๋ฌผ์ด ์์ฑ๋ ํ ์คํ๋ ๋ช ๋ น์ ์์ฑํ๋ ๋ฉ์๋ //โ ์๋ต ๊ฒฐ๊ณผ๋ฅผ ๋ณ๊ฒฝํ ๊ฒฝ์ฐ ์ฌ์ฉ @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { // TODO Auto-generated method stub HandlerInterceptor.super.afterCompletion(request, response, handler, ex); } }
๐LoginAuthInterceptor.java
โป xyz.itwill10.util ํจํค์ง์ LoginAuthInterceptor.java ํด๋์ค ์์ฑ
package xyz.itwill10.util; // import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.web.servlet.HandlerInterceptor; import xyz.itwill10.dto.Userinfo; // //๋ก๊ทธ์ธ ์ฌ์ฉ์ ๊ด๋ จ ๊ถํ ์ฒ๋ฆฌ๋ฅผ ์ํด ์์ฑ๋ Interceptor ํด๋์ค //โ ์์ฒญ ์ฒ๋ฆฌ ๋ฉ์๋์ ๋ช ๋ น ์คํ ์ ์ ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์์ด๊ฑฐ๋ ๊ด๋ฆฌ์๊ฐ ์๋ ์ฌ์ฉ์๊ฐ ํ์ด์ง๋ฅผ ์์ฒญํ ๊ฒฝ์ฐ ์๋ฌ ๋ฉ์ธ์ง๋ฅผ ์ถ๋ ฅํ๋ ํ์ด์ง์ URL ์ฃผ์๋ฅผ ์ ๋ฌํ๋ ๊ธฐ๋ฅ ์ ๊ณต public class LoginAuthInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HttpSession session=request.getSession(); Userinfo loginUserinfo=(Userinfo)session.getAttribute("loginUserinfo"); if(loginUserinfo==null) { throw new Exception("๋น์ ์์ ์ธ ์์ฒญ์ ๋๋ค."); } // return true; } }
๐servlet-context.xml
โป WEB-INF/spring/appServlet ํด๋์ ์๋ servlet-context.xml ์์
<!-- Interceptor ๊ด๋ จ ํด๋์ค๋ฅผ Spring Bean์ผ๋ก ๋ฑ๋ก --> <beans:bean class="xyz.itwill10.util.AdminAuthInterceptor" id="adminAuthInterceptor"/> <beans:bean class="xyz.itwill10.util.LoginAuthInterceptor" id="loginAuthInterceptor"/> <!-- interceptors : interceptor ์๋ฆฌ๋จผํธ๋ฅผ ๋ฑ๋กํ๊ธฐ ์ํ ์๋ฆฌ๋จผํธ --> <interceptors> <!-- interceptor : ์ธํฐ์ ํฐ ๊ธฐ๋ฅ์ ์ ๊ณตํ๊ธฐ ์ํ ๊ท์น์ ์ค์ ํ๊ธฐ ์ํ ์๋ฆฌ๋จผํธ --> <interceptor> <!-- mapping : ์ธํฐ์ ํฐ๊ฐ ๋์๋ ์์ฒญ ํ์ด์ง์ URL ์ฃผ์๋ฅผ ์ค์ ํ๋ ์๋ฆฌ๋จผํธ --> <!-- path ์์ฑ : ์์ฒญ URL ์ฃผ์๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ค์ --> <mapping path="/userinfo/write"/> <mapping path="/userinfo/modify"/> <mapping path="/userinfo/remove"/> <!-- ref : ์ธํฐ์ ํฐ ๊ธฐ๋ฅ์ ์ ๊ณตํ ๊ฐ์ฒด(Spring Bean)๋ฅผ ์ค์ ํ๋ ์๋ฆฌ๋จผํธ --> <!-- bean ์์ฑ : Spring Bean์ ์๋ณ์(beanName)๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ค์ --> <beans:ref bean="adminAuthInterceptor"/> </interceptor> <interceptor> <!-- ์ธํฐ์ ํฐ ๊ธฐ๋ฅ์ ์ ๊ณตํ ์์ฒญ URL ์ฃผ์์๋ [*] ํจํด๋ฌธ์ ์ฌ์ฉ ๊ฐ๋ฅ --> <!-- โ * : ํ์ฌ ํด๋์ ์์ฒญ ํ์ด์ง, ** : ํ์ฌ ํด๋ ๋ฐ ํ์ ํด๋ --> <!-- <mapping path="/*"/> --> <!-- <mapping path="/**"/> --> <!-- <mapping path="/userinfo/*"/> --> <!-- exclude-mapping : ์ธํฐ์ ํฐ ๊ธฐ๋ฅ์ ์ ๊ณตํ์ง ์๊ธฐ ์ํ ์์ฒญ URL ์ฃผ์๋ฅผ ์ค์ ํ๋ ์๋ฆฌ๋จผํธ --> <!-- <exclude-mapping path="/userinfo/login"/> --> <!-- --> <mapping path="/userinfo/list"/> <mapping path="/userinfo/view"/> <beans:ref bean="loginAuthInterceptor"/> </interceptor> </interceptors>