본문 바로가기

개발하자/JSP&Servlet

session.setAttribute();

주소입력:http://localhost:8090/jsp_test1/a.jsp?id=aaa&pw=bbb&addr=ccc&tel=ddd

주소입력하면 회원정보보기 클자만 보이고

그 글자를 클릭하면 파라미터로 입력한 값들이 보임

void setAttribute(String name,
                Object value)

a.jsp

==================================

<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="kr.co.seoulit.member.to.Member"%>
<%

String id=request.getParameter("id");
String pw=request.getParameter("pw");
String addr=request.getParameter("addr");
String tel=request.getParameter("tel");

Member m=new Member();
m.setId(id);
m.setPw(pw);
m.setAddr(addr);
m.setTel(tel);

session.setAttribute("member",m);
session.setAttribute("name","홍길동");
%>
<!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=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<a href="b.jsp">회원정보보기</a>
</body>
</html>

 b.jsp

========================================

<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="kr.co.seoulit.member.to.Member"%>
<%
Member m=(Member)session.getAttribute("member");
%>
<!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=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%=m.getId()%><br>
<%=m.getPw()%><br>
<%=m.getAddr()%><br>
<%=m.getTel()%><br>
</body>
</html>