예제 1
데이터 저장
//MemberDTO class에 정보 저장
MemberDTO m1 = new MemberDTO();
m1.setId("aa1"); m1.setPw("bb1"); m1.setAddr("cc1");m1.setTel("dd1");
MemberDTO m2 = new MemberDTO();
m2.setId("aa2"); m2.setPw("bb2");m2.setAddr("cc2");m2.setTel("dd2");
MemberDTO m3 = new MemberDTO();
m3.setId("aa3"); m3.setPw("bb3");m3.setAddr("cc3");m3.setTel("dd3");
List<MemberDTO> list = new ArrayList<>();
Collections 이용해서 list add
//List 객체 생성
List<MemberDTO> list = new ArrayList<>();
Collections.addAll(list, m1,m2,m3);
request 객체/ for문
String id = request.getParameter("id"); // id(key) 이용해서 value가져옴
MemberDTO findMember = null;
for(MemberDTO member:list){
if(member.getId().equals(id)){ //member에 있는 Id랑 id 같으면 출력
findMember = member;
break; // 발견하면 빠져나가는 문구
}
}
원본
class MemberDTO//경로:src.kr.co.seoulit.MemberDTO.java
더보기
package kr.co.seoulit;
public class MemberDTO {
private String id,pw,addr,tel;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPw() {
return pw;
}
public void setPw(String pw) {
this.pw = pw;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
}
t9.jsp //경로 :WebContent.t9.jsp
더보기
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@page import="java.util.Collections"%>
<%@page import="java.util.stream.Collectors"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="kr.co.seoulit.MemberDTO"%>
<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
MemberDTO m1 = new MemberDTO();
m1.setId("aa1"); m1.setPw("bb1"); m1.setAddr("cc1");m1.setTel("dd1");
MemberDTO m2 = new MemberDTO();
m2.setId("aa2"); m2.setPw("bb2");m2.setAddr("cc2");m2.setTel("dd2");
MemberDTO m3 = new MemberDTO();
m3.setId("aa3"); m3.setPw("bb3");m3.setAddr("cc3");m3.setTel("dd3");
List<MemberDTO> list = new ArrayList<>();
Collections.addAll(list, m1,m2,m3);
String id = request.getParameter("id"); // id(key) 이용해서 value가져옴
MemberDTO findMember = null;
for(MemberDTO member:list){
if(member.getId().equals(id)){ //member에 있는 Id랑 id 같으면 출력
findMember = member;
break; // 발견하면 빠져나가는 문구
}
}
%>
<h1>회원상세정보보기</h1>
ID: <input type="text" value="<%= findMember.getId() %>" > <br/>
PW: <input type="text" value="<%= findMember.getPw() %>"> <br/>
ADDR: <input type="text" value="<%= findMember.getAddr() %>"> <br/>
TEL: <input type="text"value="<%= findMember.getTel() %>"> <br/>
</body>
</html>
예제2) select 이용
원본
더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>회원목록</h1>
<select id = "sel">
<option>aa1</option>
<option>aa2</option>
<option>aa3</option>
</select>
<script>
document.querySelector("#sel").value="<%=request.getParameter("id") %>";
</script>
</body>
</html>
예제3)
t13.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href = "t14.jsp?id=<%=request.getParameter("id") %>">문서t14.jsp로 이동</a>
</body>
</html>
t.14.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- t13.jsp 보낸 id 가져옴 -->
<%= request.getParameter("id") %>
</body>
</html>
'JAVA > Web' 카테고리의 다른 글
Request객체 (0) | 2024.03.10 |
---|---|
경로 , jsp 파라매터값 전송 (0) | 2024.03.10 |
JSP프로젝트 생성하고 배포하기 (0) | 2024.03.10 |
Server Configured 설정 방법 (0) | 2024.02.23 |
Dynamci Web Project에서 DB 연결, Mybatis 이용하기 위한 설정 (0) | 2024.02.23 |