회원정보 수정 폼, 회원정보 수정 처리, 이름으로 검색, 마일리지 범위로 검색(Spring MVC, ibatis 이용)
프로그래밍/Spring MVC 2012. 7. 2. 14:38시작 : login_success.jsp, menu.jsp(getLoginMemberInfo.do)
ctr : getLoginMemberInfo()
view : 성공 : member_detail.jsp
로그인 안한 경우 : login_form.jsp
회원정보 수정 폼
시작 : member_details.jsp, menu.jsp(modifyForm.do)
ctr : modifyForm()
view : 성공 : /res/modify_form.jsp
로그인 안한경우 : login_form.jsp
회원정보 수정 처리
시작 : modifyForm.jsp( modifyMember.do )
Ctr : modifyMember()
Service : modifyMember() ->dao
view : 성공 : /res/member_detail.jsp
실패 : exception - error.jsp
로그인 안한 경우 - login_form.jsp
회원 탈퇴 처리
시작 : member_detail.jsp, menu.jsp( removeMember.do )
Ctr : removeMember(HttpSession)
Service : removeMemberById()
View : 성공 - login_form.jsp
실패 - Exception - res/error.jsp
로그인 안한 상태 - login_form.jsp
검색처리
시작 : search_form.jsp ( /searchMemberByMileageRange.do )
Ctr : searchMemberByMileageRange(int startMileage. int endMileage)
Service : searchMemberByMileageRange() ->dao
view : 성공 : /res/search_result.jsp
실패 : exception - res/error.jsp
이름으로 검색처리
시작 : search_form.jsp ( /searchMemberByName.do )
Ctr : searchMemberByName(String name)
service : searchMemberByName() =>dao
view : 성공 : /res/search_result.jsp
실패 : exception : res/error.jsp
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
<typeAlias alias="mdto" type="member.dto.MemberDTO"/>
<sql id="select" >
select id,
password,
name,
register_number1 as registerNumber1,
register_number2 as registerNumber2,
mileage
from member
</sql>
<resultMap class="mdto" id="memberRM">
<result property="id" columnIndex="1"/>
<result property="password" columnIndex="2"/>
<result property="name" columnIndex="3"/>
<result property="registerNumber1" columnIndex="4"/>
<result property="registerNumber2" columnIndex="5"/>
<result property="mileage" columnIndex="6" nullValue="-1"/>
</resultMap>
<select id="selectMemberById" parameterClass="string" resultMap="memberRM">
<include refid="select"/>
where id=#id#
</select>
<select id="selectMemberByRegisterNumber" parameterClass="hashmap" resultMap="memberRM">
<include refid="select"/>
where register_Number1=#registerNumber1#
and register_Number2=#registerNumber2#
</select>
<insert id="insertMember" parameterClass="mdto">
insert into member
(id, password, name, register_number1, register_number2, mileage)
values(#id#,#password#,#name#,#registerNumber1#,#registerNumber2#,#mileage#)
</insert>
<select id="selectAllMember" resultMap="memberRM">
<include refid="select"/>
</select>
<update id="updateMember" parameterClass="mdto">
update member
set password=#password#, name=#name#, register_number1=#registerNumber1#, register_number2=#registerNumber2#
where id=#id#
</update>
<delete id="deleteMemberById" parameterClass="string">
delete from member where id=#id#
</delete>
<select id="selectMemberByMileageRange" parameterClass="hashmap" resultMap="memberRM">
<include refid="select"/>
where mileage between #startMileage# and #endMileage#
</select>
<select id="searchByMemberName" parameterClass="string" resultMap="memberRM">
<include refid="select"/>
where name like '%$name$%'
</select>
</sqlMap>
<!-- xxxx.insert("insertMember", mdto); -->
<!-- Object obj = xxx.queryForObject("selectMemberById","abcde"); 추후 MemberDTO로 캐스팅해서 사용 -->
package member.controller;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import member.dto.MemberDTO;
import memver.model.service.MemberManageService;
@Controller
public class MemberController {
private MemberManageService service;
public MemberController(MemberManageService service){
this.service = service;
}
@RequestMapping(value="/registerMember.do")
public ModelAndView registerMember(MemberDTO mdto){
ModelAndView mv = null;
mdto.setMileage(1000);
try {
System.out.println(mdto);
service.registerMember(mdto);
System.out.println("****************");
mv = new ModelAndView("/res/register_success","mdto",mdto);
} catch (Exception e) {
e.printStackTrace();
mv = new ModelAndView("/res/error","error_message",e.getMessage());
}
return mv;
}
@RequestMapping(value="/getAllMemberInfo.do")
public ModelAndView getAllMemberInfo(){
ModelAndView mv = null;
try{
System.out.println("getMemberList()실행");
ArrayList<MemberDTO> list = service.getMemberList();
mv = new ModelAndView("/member_list","member_list",list);
}catch (Exception e) {
mv = new ModelAndView("/res/error", "error_message",e.getMessage());
}
return mv;
}
@RequestMapping(value="/login.do")
public ModelAndView login(String id, String password, HttpSession session){
ModelAndView mv = null;
try {
MemberDTO mdto = service.getMemberById(id);
if(mdto!=null){//id가 있는 경우
if(mdto.getPassword().equals(password)){//id와 password가 맞는 경우
System.out.println("login_success.jsp실행");
session.setAttribute("memberDTO", mdto);
mv = new ModelAndView("/res/login_success");
}else{//id가 맞고 비밀번호가 틀린경우
mv = new ModelAndView("/login_form","error_message",password+"는 없는 비밀번호입니다.");
}
}else{//id와 비밀번호가 틀린경우
mv = new ModelAndView("/login_form","error_message",id+"는 없는 아이디입니다.");
}
} catch (SQLException e) {
e.printStackTrace();
mv = new ModelAndView("/res/error","error_message",e.getMessage());
}
return mv;
}
@RequestMapping(value="/logout.do")
public ModelAndView logout(HttpSession session){
ModelAndView mv = null;
MemberDTO mdto = (MemberDTO) session.getAttribute("memberDTO");
if(mdto!=null){
mv = new ModelAndView("/login_form");
session.invalidate();
}else{
mv = new ModelAndView("/login_form","error_message","로그인 후 이용바랍니다.");
}
return mv;
}
@RequestMapping(value="getLoginMemberInfo.do")
public ModelAndView getLoginMemberInfo(HttpSession session){
ModelAndView mv = null;
MemberDTO mdto = (MemberDTO) session.getAttribute("memberDTO");
if(mdto!=null){
mv = new ModelAndView("/res/member_details");
}else{
mv = new ModelAndView("/login_form","error_message","로그인 후 이용바랍니다.");
}
return mv;
}
@RequestMapping("modifyForm.do")
public ModelAndView modifyForm(HttpSession session){
ModelAndView mv = null;
MemberDTO mdto = (MemberDTO) session.getAttribute("memberDTO");
if(mdto!=null){
mv = new ModelAndView("/res/modify_form");
}else{
mv = new ModelAndView("/login_form","error_message","로그인 후 이용바랍니다.");
}
return mv;
}
@RequestMapping("/modifyMember.do")
public ModelAndView modifyMember(MemberDTO mdto, HttpSession session){
ModelAndView mv = null;
System.out.println(mdto);
MemberDTO login_info = (MemberDTO) session.getAttribute("memberDTO");
if(login_info==null){//로그인 안된 경우
mv = new ModelAndView("/login_form","error_message","로그인 후 회원정보 수정바랍니다.");
}else{//로그인 된 경우
try {
System.out.println("update처리");
service.modifyMember(mdto);
// login_info.setPassword(mdto.getPassword());
session.setAttribute("memberDTO", mdto);
mv = new ModelAndView("/res/member_details");
} catch (SQLException e) {
e.printStackTrace();
mv = new ModelAndView("/res/error");
}
}
return mv;
}
@RequestMapping("removeMember.do")
public ModelAndView removeMember(HttpSession session){
MemberDTO mdto = (MemberDTO) session.getAttribute("memberDTO");
ModelAndView mv = null;
if(mdto==null){//로그인 안된 경우
mv = new ModelAndView("/login_form","error_message","로그인 후 회원 탈퇴 이용바랍니다.");
}else{
try {
service.removeMemberById(mdto.getId());
mv = new ModelAndView("/login_form");
//세션 소멸시키기
session.invalidate();
} catch (SQLException e) {
e.printStackTrace();
mv = new ModelAndView("/res/error");
}
}
return mv;
}
@RequestMapping("searchMemberByMileageRange.do")
public ModelAndView searchMemberByMileageRange(int startMileage, int endMileage,HttpServletRequest request){
ModelAndView mv = null;
ArrayList<MemberDTO> list = null;
try {
list = service.selectMemberByMileageRange(startMileage, endMileage);
request.setAttribute("title","마일리지검색");
request.setAttribute("search_value", startMileage+"~"+endMileage);
System.out.println(list);
mv = new ModelAndView("/res/search_result","searchList",list);
} catch (SQLException e) {
e.printStackTrace();
mv = new ModelAndView("/res/error","error_messge",e.getMessage());
}
return mv;
}
@RequestMapping("searchMemberByName.do")
public ModelAndView searchMemberByName(String name, HttpServletRequest request){
ModelAndView mv = null;
ArrayList<MemberDTO> list = null;
try {
list = service.getSearchByMemberName(name);
request.setAttribute("title","이름으로 검색");
request.setAttribute("search_value", name);
System.out.println(list);
mv = new ModelAndView("/res/search_result","searchList",list);
} catch (SQLException e) {
e.printStackTrace();
mv = new ModelAndView("/res/error","error_messge",e.getMessage());
}
return mv;
}
}
package member.dto;
public class MemberDTO {
private String id;
private String password;
private String name;
private String registerNumber1;
private String registerNumber2;
private int mileage;
public MemberDTO() {
super();
}
public MemberDTO(String id, String password, String name,
String registerNumber1, String registerNumber2, int mileage) {
super();
this.id = id;
this.password = password;
this.name = name;
this.registerNumber1 = registerNumber1;
this.registerNumber2 = registerNumber2;
this.mileage = mileage;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRegisterNumber1() {
return registerNumber1;
}
public void setRegisterNumber1(String registerNumber1) {
this.registerNumber1 = registerNumber1;
}
public String getRegisterNumber2() {
return registerNumber2;
}
public void setRegisterNumber2(String registerNumber2) {
this.registerNumber2 = registerNumber2;
}
public int getMileage() {
return mileage;
}
public void setMileage(int mileage) {
this.mileage = mileage;
}
@Override
public String toString() {
return "MemberDTO [id=" + id + ", password=" + password + ", name="
+ name + ", registerNumber1=" + registerNumber1
+ ", registerNumber2=" + registerNumber2 + ", mileage="
+ mileage + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + mileage;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result
+ ((password == null) ? 0 : password.hashCode());
result = prime * result
+ ((registerNumber1 == null) ? 0 : registerNumber1.hashCode());
result = prime * result
+ ((registerNumber2 == null) ? 0 : registerNumber2.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
MemberDTO other = (MemberDTO) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (mileage != other.mileage)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
if (registerNumber1 == null) {
if (other.registerNumber1 != null)
return false;
} else if (!registerNumber1.equals(other.registerNumber1))
return false;
if (registerNumber2 == null) {
if (other.registerNumber2 != null)
return false;
} else if (!registerNumber2.equals(other.registerNumber2))
return false;
return true;
}
}
package member.exception;
public class DuplicatedIdException extends Exception{
public DuplicatedIdException(){}
public DuplicatedIdException(String message){
super(message);
}
}
package member.exception;
public class DuplicatedRegisterNumberException extends Exception{
public DuplicatedRegisterNumberException(){}
public DuplicatedRegisterNumberException(String message){
super(message);
}
}
package member.model.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.tomcat.dbcp.dbcp.BasicDataSource;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import member.dto.MemberDTO;
public class MemberDAO {
private SqlMapClientTemplate sqlMap;
public MemberDAO(SqlMapClientTemplate sqlMap){
this.sqlMap = sqlMap;
}
public MemberDTO selectMemberById(String id) {
// TODO Auto-generated method stub
return (MemberDTO) sqlMap.queryForObject("selectMemberById", id);
}
//주민번호로 조회
public MemberDTO selectMemberByRegisterNumber(String rN1, String rN2) throws SQLException{
HashMap<String, String> map = new HashMap<String, String>();
map.put("registerNumber1", rN1);
map.put("registerNumber2", rN2);
System.out.println("selectMemberByRegisterNumber ");
return (MemberDTO)sqlMap.queryForObject("selectMemberByRegisterNumber",map);
}
//회원데이터 insert메소드
public Object insertMember(MemberDTO mdto) throws SQLException{
return sqlMap.insert("insertMember", mdto);
}
public ArrayList<MemberDTO> selectAllMember() {
return (ArrayList<MemberDTO>) sqlMap.queryForList("selectAllMember");
}
//회원 데이터 update
public int updateMember(MemberDTO mto) {
return sqlMap.update("updateMember", mto);
}
public int deleteMemberById(String id) {
return sqlMap.delete("deleteMemberById", id);
}
public ArrayList<MemberDTO> selectMemberByMileageRange(int startMileage, int endMileage) {
HashMap map = new HashMap();
map.put("startMileage", startMileage);
map.put("endMileage",endMileage);
System.out.println("map : "+map);
return (ArrayList<MemberDTO>) sqlMap.queryForList("selectMemberByMileageRange", map);
}
public ArrayList<MemberDTO> searchByMemberName(String name) {
return (ArrayList<MemberDTO>) sqlMap.queryForList("searchByMemberName", name);
}
}
package memver.model.service;
import java.sql.SQLException;
import java.util.ArrayList;
import member.dto.MemberDTO;
import member.exception.DuplicatedIdException;
import member.exception.DuplicatedRegisterNumberException;
import member.model.dao.MemberDAO;
//회원 관리 비지니스 로직을 처리하는 Business Service 클래스
public class MemberManageService {
private MemberDAO dao;
public MemberManageService(MemberDAO dao){
this.dao = dao;
}
//가입 처리 메소드
public void registerMember(MemberDTO mto)throws SQLException, DuplicatedIdException, DuplicatedRegisterNumberException{
//1. 등록된 ID가 있는 지 체크
// - 이미 등록된 ID라면 DuplicatedIdException를 발생시킨다.
if(dao.selectMemberById(mto.getId())!=null){
throw new DuplicatedIdException(mto.getId()+"는 이미등록된 아이디 입니다.");
}
//2. 등록된 주민번호가 있는 지 체크
// - 이미 등록된 주민번호라면 DuplicatedRegisterNumberException 발생시킨다.
if(dao.selectMemberByRegisterNumber(mto.getRegisterNumber1(), mto.getRegisterNumber2())!=null){
throw new DuplicatedRegisterNumberException("는 이미 가입된 주민번호 입니다.");
}
//3. 디비에 회원정보 등록 처리
dao.insertMember(mto);
}
//전체 회원목록 조회
public ArrayList<MemberDTO> getMemberList() throws SQLException{
return dao.selectAllMember();
}
//마일리지 범위로 조회
public ArrayList<MemberDTO> selectMemberByMileageRange(int startMileage, int endMileage)throws SQLException {
return dao.selectMemberByMileageRange(startMileage, endMileage);
}
//ID로 회원 목록조회
public MemberDTO getMemberById(String id) throws SQLException{
return dao.selectMemberById(id);
}
//회원정보 수정
//update메소드
public void modifyMember(MemberDTO mto) throws SQLException{
int cnt = dao.updateMember(mto);
System.out.println(cnt+"개의 행이 업데이트 되었습니다.");
}
public void removeMemberById(String id)throws SQLException {
int cnt = dao.deleteMemberById(id);
System.out.println(cnt+"개의 행이 삭제되었습니다.");
}
public ArrayList<MemberDTO> getSearchByMemberName(String name) throws SQLException{
return dao.searchByMemberName(name);
}
}
<%@ 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>Insert title here</title>
</head>
<body>
<jsp:include page="/menu.jsp"/>
<c:if test="${requestScope.error_message!=null }">
실행 도중 오류가 발생했습니다.<br>
오류 내용 ${error_message }
</c:if>
<a href='/${initParam.context_root }/index.jsp'>메인페이지로 이동</a>
</body>
</html>
<%@page import="member.dto.MemberDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="/menu.jsp"/>
${sessionScope.memberDTO.id } 님환영합니다.<p>
이름 : ${sessionScope.memberDTO.name }<br>
패스워드 : ${sessionScope.memberDTO.password }<br>
주민번호 : ${sessionScope.memberDTO.registerNumber1 }-${sessionScope.memberDTO.registerNumber2 }<br>
마일리지 : ${sessionScope.memberDTO.mileage }<br>
<a href='/${initParam.context_root }/logout.do'>로그아웃</a>
<a href='/${initParam.context_root }/getLoginMemberInfo.do'>회원정보조회(로그인한 회원의 정보)</a>
<!--<input type="button" value="회원정보조회" onClick="location.href='/${initParam.context_root }/getMemberInfo'"> -->
</body>
</html>
<%@page import="member.dto.MemberDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="/menu.jsp"/>
<h2>회원정보보기</h2><p>
아이디 : ${sessionScope.memberDTO.id }<br>
이름 : ${sessionScope.memberDTO.name }<br>
주민번호 : ${sessionScope.memberDTO.registerNumber1 }-${sessionScope.memberDTO.registerNumber2 }<br>
마일리지 : ${sessionScope.memberDTO.mileage }<br>
<p>
<a href="/${initParam.context_root }/modifyForm.do">회원정보수정</a>
<a href="/${initParam.context_root }/removeMember.do">회원 탈퇴</a>
</p>
</body>
</html>
<%@page import="member.dto.MemberDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function modifyCheck(){
var pwd = document.modify_form.password;
var name = document.modify_form.name;
var registerNumber1 = document.modify_form.registerNumber1;
var registerNumber2 = document.modify_form.registerNumber2;
if(pwd.value==""){
alert("비밀번호를 입력해 주세요.");
pwd.focus();
return false;
}
if(name.value==""){
alert("이름을 입력해 주세요.");
name.focus();
return false;
}
if(registerNumber1.value==""){
alert("주민번호를 입력해 주세요.");
registerNumber1.focus();
return false;
}
if(registerNumber2.value==""){
alert("주민번호를 입력해 주세요.");
registerNumber2.focus();
return false;
}
if(registerNumber1.value.length!=6){
alert("주민번호 앞자리 6자리를 입력해 주세요.");
registerNumber1.focus();
return false;
}
if(registerNumber2.value.length!=7){
alert("주민번호 뒷자리 7자리를 입력해 주세요.");
registerNumber1.focus();
return false;
}
}
</script>
</head>
<body>
<jsp:include page="/menu.jsp"/>
<h2>회원정보수정</h2><hr><p>
<form action="/${initParam.context_root }/modifyMember.do" method="post" name="modify_form" onsubmit="return modifyCheck()">
<input type="hidden" name="command" value="member_modify">
<input type="hidden" name="id" value="${sessionScope.memberDTO.id }">
<input type="hidden" name="mileage" value="${sessionScope.memberDTO.mileage }">
<table width="500">
<tr>
<td>아이디</td><td>${sessionScope.memberDTO.id }</td>
</tr>
<tr>
<td>비밀번호</td><td><input type="text" name="password"></td>
</tr>
<tr>
<td>이름</td><td><input type="text" name="name" value="${sessionScope.memberDTO.name }"></td>
</tr>
<tr>
<td>주민번호</td><td><input type="text" name="registerNumber1" value="${sessionScope.memberDTO.registerNumber1 }">-<input type="text" name="registerNumber2" value="${sessionScope.memberDTO.registerNumber2 }"></td>
</tr>
<tr>
<td>마일리지 ${sessionScope.memberDTO.mileage }</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="정보수정"><input type="reset" value="다시작성"></td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="member.dto.MemberDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="/menu.jsp"/>
<h2>수정된 정보</h2><hr><p>
아이디 : ${sessionScope.memberDTO.id }<br>
비밀번호 : ${sessionScope.memberDTO.password }<br>
이름 : ${sessionScope.memberDTO.name }<br>
주민번호 : ${sessionScope.memberDTO.registerNumber }<br>
마일리지 : ${sessionScope.memberDTO.mileage }<br>
</body>
</html>
<%@page import="member.dto.MemberDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="/menu.jsp"/>
<h2>가입 환영합니다.</h2>
<h3>가입 시 입력한 정보입니다. </h3>
ID : ${requestScope.mdto.id }
Password : ${requestScope.mdto.password }
이름 : ${requestScope.mdto.name }
주민번호 : ${requestScope.mdto.registerNumber1 } - ${requestScope.mdto.registerNumber2 }
마일리지 : ${requestScope.mdto.mileage }<p>
<a href="/${initParam.context_root }/login_form.jsp">로그인</a>
<a href="/${initParam.context_root }/index.jsp">메인페이지</a>
</body>
</html>
<%@ 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>Insert title here</title>
</head>
<body>
<jsp:include page="/menu.jsp"/>
<h2> ${requestScope.title } </h2><hr><p>
조회조건 : ${requestScope.search_value }
<table width="500" border="1" cellspacing="0">
<tr align="center">
<td>순번</td><td>아이디</td><td>이름</td><td>주민번호</td><td>마일리지</td>
</tr>
<c:forEach items="${requestScope.searchList }" var="member_list" varStatus="cnt">
<tr align="center">
<td>${cnt.count }</td><td>${member_list.id }</td><td><a href="/servlet_member/SearchMemberByID?id=${member_list.id }">${member_list.name }</a></td><td>${member_list.registerNumber1 }-${member_list.registerNumber2 }</td><td>${member_list.mileage }</td>
</tr>
</c:forEach>
</table>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- View Resolver등록 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="suffix" value=".jsp"/>
</bean>
<!-- DataSource 등록 -->
<bean name="datasource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:XE"/>
<property name="username" value="scott"/>
<property name="password" value="tiger"/>
</bean>
<!-- SqlMapClientFactoryBean -->
<bean name="sqlMapClientFactoryBean" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="/WEB-INF/SqlMapConfig.xml"/>
<property name="dataSource" ref="datasource"/>
</bean>
<!-- SqlMapClientTemplate -->
<bean name="sqlMapclient" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClientFactoryBean"/>
</bean>
<!-- MemberDAO -->
<bean name="memberDAO" class="member.model.dao.MemberDAO">
<constructor-arg ref="sqlMapclient"/>
</bean>
<!-- MemberManageService -->
<bean name="memberManageService" class="memver.model.service.MemberManageService">
<constructor-arg ref="memberDAO"/>
</bean>
<!-- MemberController -->
<bean name="memberController" class="member.controller.MemberController">
<constructor-arg ref="memberManageService"/>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<sqlMap resource="member/config/member.xml"/>
</sqlMapConfig>
<?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">
<!-- DispatcherServlet 등록 -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/member-spring.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup><!-- 어플리케이션 시작시점에 load 되게 해준다. -->
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 한글 encoding 처리 -->
<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>
<!-- ContextParam 등록하기 -->
<context-param>
<param-name>context_root</param-name>
<param-value>member_springmvc</param-value>
</context-param>
</web-app>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="/menu.jsp"/>
<h1>회원관리</h1>
<a href='/${initParam.context_root }/register_form.jsp'>회원가입폼</a><br>
<a href='/${initParam.context_root }/login_form.jsp'>로그인폼</a>
<a href='/${initParam.context_root }/controller?command=member_list'>전체 회원 조회</a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:if test="${sessionScope.memberDTO != null }">
<jsp:forward page="/res/member_details.jsp"/>
</c:if>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function loginCheck(){
var id = document.login_form.id;
var pwd = document.login_form.password;
if(id.value==""){
alert("아이디를 입력해 주세요.");
id.focus();
return false;
}
if(pwd.value==""){
alert("비밀번호를 입력해 주세요.");
pwd.focus();
return false;
}
}
</script>
</head>
<c:if test="${requestScope.error_message!=null }">
<font color="red">${requestScope.error_message }</font>
</c:if><br>
<body>
<jsp:include page="/menu.jsp"/>
<form action="/${initParam.context_root }/login.do" method="post" name="login_form" onsubmit="return loginCheck()">
<input type="hidden" name="command" value="login">
<table>
<tr>
<td><h2>로그인</h2><p></td>
</tr>
<tr>
<td>id</td><td><input type="text" name="id"></td>
</tr>
<tr>
<td>password</td><td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="로그인"><input type="reset" value="초기화"></td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="member.dto.MemberDTO"%>
<%@page import="java.util.ArrayList"%>
<%@ 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>Insert title here</title>
<body>
<jsp:include page="/menu.jsp"/>
<h2>모든 회원 목록조회</h2><hr><p>
<table width="500" border="1" cellspacing="0">
<tr align="center">
<td>순번</td><td>아이디</td><td>이름</td><td>주민번호</td><td>마일리지</td>
</tr>
<c:forEach items="${requestScope.member_list }" var="member_list" varStatus="cnt">
<tr align="center">
<td>${cnt.count }</td><td>${member_list.id }</td><td><a href="/servlet_member/SearchMemberByID?id=${member_list.id }">${member_list.name }</a></td><td>${member_list.registerNumber1 }-${member_list.registerNumber2 }</td><td>${member_list.mileage }</td>
</tr>
</c:forEach>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<a href='/${initParam.context_root }/index.jsp'>메인페이지</a>
<c:choose>
<c:when test="${sessionScope.memberDTO == null }">
<a href='/${initParam.context_root }/register_form.jsp'>회원가입폼</a>
<a href="/${initParam.context_root }/login_form.jsp">로그인폼</a>
<a href="/${initParam.context_root }/search_form.jsp">검색</a>
</c:when>
<c:otherwise>
<a href='/${initParam.context_root }/logout.do'>로그아웃</a>
<a href="/${initParam.context_root }/getLoginMemberInfo.do">회원정보조회</a>
<a href="/${initParam.context_root }/modifyForm.do">회원정보 수정</a>
<a href="/${initParam.context_root }/controller?command=member_remove">회원 탈퇴</a>
</c:otherwise>
</c:choose>
<a href="/${initParam.context_root }/getAllMemberInfo.do">전체 회원정보 조회</a>
<hr width="700" align="left" noshade="noshade">
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function registerCheck(){
var id = document.register_form.id;
var pwd = document.register_form.password;
var name = document.register_form.name;
var registerNumber1 = document.register_form.registerNumber1;
var registerNumber2 = document.register_form.registerNumber2;
if(id.value==""){
alert("아이디를 입력해 주세요.");
id.focus();
return false;
}
if(pwd.value==""){
alert("비밀번호를 입력해 주세요.");
pwd.focus();
return false;
}
if(name.value==""){
alert("이름을 입력해 주세요.");
name.focus();
return false;
}
if(registerNumber1.value==""){
alert("주민번호를 입력해 주세요.");
registerNumber1.focus();
return false;
}
if(registerNumber1.value.length!=6){
alert("주민번호 앞자리 6자리를 입력해 주세요.");
registerNumber1.focus();
return false;
}
if(registerNumber2.value==""){
alert("주민번호를 입력해 주세요.");
registerNumber2.focus();
return false;
}
if(registerNumber2.value.length!=7){
alert("주민번호 뒷자리 7자리를 입력해 주세요.");
registerNumber1.focus();
return false;
}
}
</script>
</head>
<body>
<jsp:include page="/menu.jsp"/>
<form action="/${initParam.context_root }/registerMember.do" method="post" name="register_form" onsubmit="return registerCheck()">
<table border="1">
<tr>
<td align="center">id</td><td><input type="text" name="id" maxlength="10" size="10"></td>
</tr>
<tr>
<td align="center">pwd</td><td><input type="password" name="password" maxlength="4" size="4"></td>
</tr>
<tr>
<td align="center">이름 : </td><td><input type="text" name="name" maxlength="10" size="10"></td>
</tr>
<tr>
<td align="center">주민번호 : </td>
<td>
<input type="text" name="registerNumber1" maxlength="6" size="6">-
<input type="text" name="registerNumber2" maxlength="7" size="7">
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="가입">
<input type="reset" value="다시작성"></td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function mileageSearchFormCheck(){
var startMileage = document.mileage_search_form.startMileage;
var endMileage = document.mileage_search_form.endMileage;
if(startMileage.value==""){
alert("시작 마일리지를 입력해 주세요.");
startMileage.focus();
return false;
}
if(endMileage.value==""){
alert("끝마일리지를 입력해 주세요.");
endMileage.focus();
return false;
}
if(parseInt(startMileage.value)>parseInt(endMileage.value)){
alert("시작마일리지가 끝마일리지보다 작아야 합니다. 다시 입력해 주세요.");
startMileage.focus();
return false;
}
if(isNaN(startMileage.value)||isNaN(endMileage.value)){
alert("마일리지는 숫자를 입력하십시오.");
return false;
}
}
function nameSearchFormCheck(){
var name = document.name_search_form.name;
if(name.value==""){
alert("이름를 입력해 주세요.");
name.focus();
return false;
}
}
</script>
</head>
<body>
<font size="2" color="red">${requestScope.error_message }</font><br>
마일리지 검색하기<hr><p>
<form action="/${initParam.context_root }/searchMemberByMileageRange.do" method="post" name="mileage_search_form" onsubmit="return mileageSearchFormCheck()">
범위 : <input type = "text" name="startMileage">~<input type = "text" name="endMileage">
<input type="submit" value="검색">
</form>
<br>
<form action="/${initParam.context_root }/searchMemberByName.do" method="post" name="name_search_form" onsubmit="return nameSearchFormCheck()"><!-- 만약에버튼으로 만들었을 때는 onclick으로 해놓고 함수에서 form.submit()을 해줘야한다. -->
이름 : <input type="text" name="name">
<input type="submit" value="이름으로 검색">
</form>
</body>
</html>
* 결과
'프로그래밍 > Spring MVC' 카테고리의 다른 글
FileUpload실습 - DTO를 통해받기, @RequestParam, MultipartHttpServletRequest이용 (0) | 2012.07.04 |
---|---|
FileUpload(파일 업로드) (0) | 2012.07.04 |
로그인, 로그아웃 처리 (0) | 2012.07.02 |
spring, jstl, ibatis 연동하여 사용하기 실습- member_springmvc (0) | 2012.06.29 |
Annotation - HttpServletRequest, HttpServletResponse, HttpSession, @CookieValue[실습] (0) | 2012.06.28 |