
-request.getParameter๋ก ๋ฐ์ ๋ฐ์ดํฐ๋ ํด๋นํ์ด์ง์์๋ง ์ฌ์ฉํด์ผ์ง, ๋ค๋ฅธ ํ์ผ๋ก ๋๊ฒจ์ค ์ ์์.
โ๏ธ Test1.
๐ป ์ ๋ ฅ
ํ๋ฉด1 : calendar
์์ด form - get๋ฐฉ์์ด์ง๋ง ์๊ธฐ์์ ์ ํธ์ถํ ์ ์๋๋กํ๋ฉด2 : calendar_ok
a href="calendar.jsp?year=<%preYear %>&month=<%preMonth %>"
calendar.jsp
<%@page import="java.util.Calendar"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
Calendar cal = Calendar.getInstance(); //์บ๋ฆฐ๋๋ง์ ๊ฐ์ฒด์์ฑ
int nowYear = cal.get(Calendar.YEAR);
int nowMonth = cal.get(Calendar.MONTH)+1;
int nowDay = cal.get(Calendar.DAY_OF_MONTH);
//์ฌ์ฉ์๊ฐ get๋ฐฉ์์ผ๋ก ๋๊ฒจ์ฃผ๋ฉด์ ํ์ํ๊ณ ์ถ์ ๋
,์
String strYear = request.getParameter("year");
String strMonth = request.getParameter("month");
//๋ฌ๋ ฅ์ ํ์ํ ๋
, ์
//์ฒ์ ์์ํ ๋๋ ๋์ด์ค๋ gP๊ฐ ์์ด์ null์ด๋ฏ๋ก, ๋ฌด์กฐ๊ฑด system-now๋ก ๋จผ์ ๋ง๋ค์ด์ผ ํจ
int year = nowYear;
int month = nowMonth;
//2๋ฒ์งธ ์คํ
if (strYear != null) {
year = Integer.parseInt(strYear); //์ ์๋ก ๋ฐ๊พธ๋ ์ด์ : +1 , -1 ํด์ค์ผํ๋๊น
}
if (strMonth != null) {
month = Integer.parseInt(strMonth);
}
//1์ ์ ๋ฌ - ์ ๋
๋ 12์
int preYear = year, preMonth = month - 1;
if (preMonth < 1) {// 23.12 <- 24.01
preYear = year - 1;
preMonth = 12;
}
//12์ ๋ค์ ๋ฌ์ ๋ค์ํด 1์
int nextYear = year, nextMonth = month + 1;
if (nextMonth > 12) {
nextYear = year + 1;
nextMonth = 1;
}
//ํ์ํ ๋ฌ๋ ฅ ์
ํ
//1 : ๋งค๋ฌ์ ์ฒซ๋ ์ 1
cal.set(year,month-1,1);
int startDay = 1;
int endDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
//๋ฌ๋ ฅ๋ง๋ค ๋ ์ฃผ์ ์๊ฐ ํ์ํจ
//(year๋
month์ 1์ผ์ ์์ผ๊ตฌํ๊ธฐ)
int week = cal.get(Calendar.DAY_OF_WEEK);
%>
<!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>
<style type="text/css">
body {
font-size: 11pt;
}
td {
font-size: 11pt;
}
</style>
</head>
<body>
<br/><br/>
<table align="center" width="210" cellpadding="2" cellspacing="1">
<tr>
<td align="center">
<a href="calendar.jsp?year=<%=preYear %>&month=<%=preMonth %>">โ</a>
<b> <%=year %>๋
<%=month %>์ </b>
<a href="calendar.jsp?year=<%=nextYear %>&month=<%=nextMonth %>">โถ</a>
</td>
</tr>
</table>
<table align="center" width="210" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#e6e4e6" align="center"><font color="red">์ผ</font></td>
<td bgcolor="#e6e4e6" align="center">์</td>
<td bgcolor="#e6e4e6" align="center">ํ</td>
<td bgcolor="#e6e4e6" align="center">์</td>
<td bgcolor="#e6e4e6" align="center">๋ชฉ</td>
<td bgcolor="#e6e4e6" align="center">๊ธ</td>
<td bgcolor="#e6e4e6" align="center"><font color="blue">ํ </font></td>
</tr>
<%
int newLine = 0;
out.print("<tr height='20'>");
for(int i=1; i<week; i++){
out.print("<td bgcolor='#ffffff'> </td>"); //<td> ๊ณต๋ฐฑ์ ์ํ td </td>
newLine++;
}
for(int i=startDay;i<=endDay; i++){
//์ผ์์ผ์ red, ํ ์์ผ์ blue, ํ์ผ์ black, ์ค๋ color
String fontColor = (newLine==0)?"red":(newLine==6)?"blue":"black";
String bgColor = (nowYear==year)&&(nowMonth==month)&&(nowDay==i)?"#e6e4e6":"#ffffff";
out.print("<td align='center' bgcolor='"+ bgColor + "'><font color='" + fontColor + "'>" + i +
"</font></td>");
//<td align='center' bgcolor='#e6e4e6'>
//<font color ='black'>8(์ผ)</font></td>
newLine++;
if(newLine==7 && i != endDay){//0~6๊น์ง๊ฐ 1์ฃผ๋๊น
out.print("</tr><tr height='20'>"); //</tr>๋ก ์ค๋ฐ๊พธ๊ณ , <tr> ๋ค์ tr์ด๊ธฐ
newLine=0;
}
}
while(newLine>0 && newLine<7){
out.print("<td bgcolor = '#ffffff'> </td>");
newLine++;
}
out.print("</tr>"); // 128line <tr>๋ซ์์ฃผ๊ธฐ
%>
</table>
</body>
</html>
๐ ์ถ๋ ฅ
์ฃผ์๊ฐ์ด๋ ํญ์ ๋ง๊ฒ ๋์ค๋์ง ๋น๊ตํ๊ธฐ

โถ ๋๋ฅด๋ฉด ๋ค์๋ฌ

โ ๋๋ฅด๋ฉด ์ ๋ฌ

โ๏ธ Test2.
Redirect / Forward
: ๋๋ฒ์งธ ->๋ฅผ ๋ธ๋ผ์ฐ์ ๊ฐ ํ๋๋ ์คํ๋ง ๋ด๋ถ์์ ํ๋๋์ ์ฐจ์ด
: [์ค๋ช ์ ๋์ด์์] ์ถ์ฒ https://doublesprogramming.tistory.com/63
Redirect: client๋ ์๋ฒ์์ ์๋ a.jspํํ ์์ฒญํ์ง๋ง, ์์ผ๋๊น ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ด๊ณ ์๋ result.jsp๋ก ๋ฐ๋ (์ฃผ์๊ฐ ๋ฐ๋)
- ex) ์๋ฒํํ DB์ INSERT/DELETE/UPDATE/SESSION์์ผ์ค
: client๊ฐ 3๋ฒ์ ์์ฒญํ์ง๋ง a.jsp๋ ์์ผ๋๊น DB์ INSERT๋ฅผ ํด์ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ Result.jsp์ ๋ฃ์ด์ฃผ๊ณ (์ฃผ์๋ฐ๋) , ๊ทธ ์ดํ์ client์๊ฒ ํ์ธํด๋ด๋ผ~- ๋ณด์ ์ทจ์ฝ
Forward: client๊ฐ a.jsp์ ์์ฒญ์ ํด์ ์๊ฐ์ง๊ณ ์์ง๋ง, result.jsp์์ ๋ง๋ค์ด์ ๊ทธ ๋ง๋ ๊ฒฐ๊ณผ๋ฅผ ์๊ธฐ๊ฐ a.jsp๊ฐ ๊ทธ๋๋ก ๊ฐ์ง๊ณ ์ด. (์ฃผ์๊ฐ ์๋ฐ๋)
- ex) servelt : ์ฃผ๋ก forward๋ฅผ ์ (redirect๋ ์)
-> ํด๋ผ์ด์ธํธ์๊ฒ๋ test_for๋ก ๋ณด์ฌ์ง์ง๋ง, ์ฌ์ค result์์ ์ด๋ฃจ์ด์ง๊ณ ์์ด์ ๋ณด์์ ๊ฐํจ.
:jsp๋ servelt์ด ์์ - redirect์
ํด๋ผ์ด์ธํธ ์ปดํจํฐ ใ ฃ Server (์ด ์์ .jsp / result.jsp - file์ด ๋ง๋ค์ด์ ธ์์)
<onclick="this.form.action='test1_red.jsp'">
์๋ฒ -> request -> ํด๋ผ์ด์ธํธ
ํด๋ผ์ด์ธํธ -> response -> ์๋ฒ





๐ป ์ ๋ ฅ
test1.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
%>
<!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>
<form action="" method="post">
์ด๋ฆ : <input type="text" name="name"><br/>
<input type="submit" value="๋ฆฌ๋ค์ด๋ ํธ"
onclick="this.form.action='test1_red.jsp'">
<input type="submit" value="ํฌ์๋"
onclick="this.form.action='test1_for.jsp'">
</form>
</body>
</html>
test1_red
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
String name = request.getParameter("name");
//๋ฆฌ๋ค์ด๋ ํธ(์์ ๋ฐ์ name์ "result.jsp"๋ก ๊ฐ๋ผ๊ณ ํด๋ผ์ด์ธํธํํ
๋์๊ฐ์ ๋งํจ)
//๊ธธ์ด ๊บพ์ฌ๋ฒ๋ฆฐ๊ฑด name์ด null๊ฐ์ (์ฃผ์๋ฐ๋)
response.sendRedirect("result.jsp");
%>
<!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>
์ด๋ฆ: <%=name %>
</body>
</html>
test1_for
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
String name = request.getParameter("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=UTF-8">
<title>Insert title here</title>
</head>
<body>
์ด๋ฆ: <%=name %>
<jsp:forward page="result.jsp"/>
</body>
</html>
result
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
String name = request.getParameter("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=UTF-8">
<title>Insert title here</title>
</head>
<body>
๋ฆฌ๋ค์ด๋ ํธ ๋๋ ํฌ์๋ ํ์ด์ง<br/>
์ด๋ฆ: <%=name %>
</body>
</html>
โ๏ธ Test3.
๋ก๊ทธ์ธ/๋ก๊ทธ์์ ์ฒ๋ฆฌ = session ์ด์ฉ
- session : ๊ณตํต์ผ๋ก ์ฌ์ฉํ๋ ์ ์ฅ๊ณต๊ฐ์ผ๋ก, [ํ๋์ ํ๋ก์ ํธ ์์์๋ง] ๋ค๋ฅธ ํด๋์์๋ ๊ฐ๋ฅํจ

ex) ํ์ด์ง๊ฐ ๋ฐ๋์์ ๋, ๋๋ค์ ๊ณ์ ๋์ค๋๊ฑฐ - (session๊ณต๊ฐ์ ์๋ ๋๋ค์ ๋ถ๋ฌ์ค๋ ๊ฒ)


-๋ก๊ทธ์ธ์ ํ๋ฉด ์ผ๋ฐ์ ์ผ๋ก main์ฐฝ์ผ๋ก ๋์๊ฐ
๊ทผ๋ฐ login_ok์์ ๋จธ๋ฌผ๋ฌ์์

-> ๊ทธ๋์ session์ redirect ๋ฅผ ํด์ผํจ
(๋ฐ์ดํฐ๊ฐ ๋ฐ๊ผ์ผ๋๊น)


- session์์์ ์ฐพ๋ ์ฝ๋ฉ
- login_ok ๋ค๋ ์ค๋ฉด Id๊ฐ ์๊ธฐ๋๊น null๊ฐ์์ ๋ฒ์ด๋จ


๐ป ์ ๋ ฅ
login.jsp
<%@page import="java.util.Calendar"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
String userId = (String)session.getAttribute("userId");
//session.setMaxInactiveInterval(30*60); //30๋ถ
//session.setMaxInactiveInterval(5);//5์ด
Calendar cal = Calendar.getInstance(); //์บ๋ฆฐ๋๋ง์ ๊ฐ์ฒด์์ฑ
int nowYear = cal.get(Calendar.YEAR);
int nowMonth = cal.get(Calendar.MONTH)+1;
int nowDay = cal.get(Calendar.DAY_OF_MONTH);
//์ฌ์ฉ์๊ฐ get๋ฐฉ์์ผ๋ก ๋๊ฒจ์ฃผ๋ฉด์ ํ์ํ๊ณ ์ถ์ ๋
,์
String strYear = request.getParameter("year");
String strMonth = request.getParameter("month");
//๋ฌ๋ ฅ์ ํ์ํ ๋
, ์
//์ฒ์ ์์ํ ๋๋ ๋์ด์ค๋ gP๊ฐ ์์ด์ null์ด๋ฏ๋ก, ๋ฌด์กฐ๊ฑด system-now๋ก ๋จผ์ ๋ง๋ค์ด์ผ ํจ
int year = nowYear;
int month = nowMonth;
//2๋ฒ์งธ ์คํ
if (strYear != null) {
year = Integer.parseInt(strYear); //์ ์๋ก ๋ฐ๊พธ๋ ์ด์ : +1 , -1 ํด์ค์ผํ๋๊น
}
if (strMonth != null) {
month = Integer.parseInt(strMonth);
}
//1์ ์ ๋ฌ - ์ ๋
๋ 12์
int preYear = year, preMonth = month - 1;
if (preMonth < 1) {// 23.12 <- 24.01
preYear = year - 1;
preMonth = 12;
}
//12์ ๋ค์ ๋ฌ์ ๋ค์ํด 1์
int nextYear = year, nextMonth = month + 1;
if (nextMonth > 12) {
nextYear = year + 1;
nextMonth = 1;
}
//ํ์ํ ๋ฌ๋ ฅ ์
ํ
//1 : ๋งค๋ฌ์ ์ฒซ๋ ์ 1
cal.set(year,month-1,1);
int startDay = 1;
int endDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
//๋ฌ๋ ฅ๋ง๋ค ๋ ์ฃผ์ ์๊ฐ ํ์ํจ
//(year๋
month์ 1์ผ์ ์์ผ๊ตฌํ๊ธฐ)
int week = cal.get(Calendar.DAY_OF_WEEK);
%>
<!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>
<style type="text/css">
body {
font-size: 11pt;
}
td {
font-size: 11pt;
}
</style>
<script type="text/javascript">
function sendIt() {
let f = document.myForm;
if(!f.userId.value){
alert("์์ด๋ ์
๋ ฅ!");
f.userId.focus();
return;
}
if(!f.userPwd.value){
alert("ํจ์ค์๋ ์
๋ ฅ!");
f.userPwd.focus();
return;
}
f.submit();
}
</script>
</head>
<body>
<br/>
<table border="1" width="600" align="center" style="font-size: 9pt;">
<tr height="20">
<td colspan="2" align="right">
| ๊ฒ์ํ |
<%if(userId==null){%>
์ผ์ ๊ด๋ฆฌ
<%}else{ %>
<a href="schedule.jsp">์ผ์ ๊ด๋ฆฌ</a>
<%} %>
|
</td>
</tr>
<tr height="400">
<td width="200" valign="top">
<%if(userId==null){%>
<form action="login_ok.jsp" method="post" name="myForm">
์์ด๋: <input type="text" name="userId" size="10"/><br/>
ํจ์ค์๋: <input type="password" name="userPwd" size="10"/><br/>
<input type="button" value="๋ก๊ทธ์ธ" onclick="sendIt();"/>
</form>
<%}else{ %>
<b><%=userId %></b>๋ ์๋
ํ์ธ์<br/>
<a href="logout.jsp">๋ก๊ทธ์์</a>
<%} %>
</td>
<td valign="middle" align="center">
<%if(userId==null){%>
<b>๋ก๊ทธ์ธํ๋ฉด ์๋ก์ด ์ธ์์ด ๋ณด์
๋๋ค. </b>
<%}else{ %>
<!-- ************************************ -->
<table align="center" width="210" cellpadding="2" cellspacing="1">
<tr>
<td align="center">
<a href="login.jsp">
<img alt = "today" src="../jsp3/image/today.png" align="left"/></a>
<a href="login.jsp?year=<%=preYear %>&month=<%=preMonth %>">โ</a>
<b> <%=year %>๋
<%=month %>์ </b>
<a href="login.jsp?year=<%=nextYear %>&month=<%=nextMonth %>">โถ</a>
</td>
</tr>
</table>
<table align="center" width="210" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#e6e4e6" align="center"><font color="red">์ผ</font></td>
<td bgcolor="#e6e4e6" align="center">์</td>
<td bgcolor="#e6e4e6" align="center">ํ</td>
<td bgcolor="#e6e4e6" align="center">์</td>
<td bgcolor="#e6e4e6" align="center">๋ชฉ</td>
<td bgcolor="#e6e4e6" align="center">๊ธ</td>
<td bgcolor="#e6e4e6" align="center"><font color="blue">ํ </font></td>
</tr>
<%
int newLine = 0;
out.print("<tr height='20'>");
for(int i=1; i<week; i++){
out.print("<td bgcolor='#ffffff'> </td>"); //<td> ๊ณต๋ฐฑ์ ์ํ td </td>
newLine++;
}
for(int i=startDay;i<=endDay; i++){
//์ผ์์ผ์ red, ํ ์์ผ์ blue, ํ์ผ์ black, ์ค๋ color
String fontColor = (newLine==0)?"red":(newLine==6)?"blue":"black";
String bgColor = (nowYear==year)&&(nowMonth==month)&&(nowDay==i)?"#e6e4e6":"#ffffff";
out.print("<td align='center' bgcolor='"+ bgColor + "'><font color='" + fontColor + "'>" + i +
"</font></td>");
//<td align='center' bgcolor='#e6e4e6'>
//<font color ='black'>8(์ผ)</font></td>
newLine++;
if(newLine==7 && i != endDay){//0~6๊น์ง๊ฐ 1์ฃผ๋๊น
out.print("</tr><tr height='20'>"); //</tr>๋ก ์ค๋ฐ๊พธ๊ณ , <tr> ๋ค์ tr์ด๊ธฐ
newLine=0;
}
}
while(newLine>0 && newLine<7){
out.print("<td bgcolor = '#ffffff'> </td>");
newLine++;
}
out.print("</tr>"); // 128line <tr>๋ซ์์ฃผ๊ธฐ
%>
</table>
<%} %>
</td>
</tr>
</table>
</body>
</html>
๋ก๊ทธ์ธ ์

๋ก๊ทธ์ธ ํ

login_ok.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
String userId = request.getParameter("userId");
String userPwd = request.getParameter("userPwd");
if(userId.equals("suzi") && userPwd.equals("a123")){
session.setAttribute("userId", userId); //"๋ง๋ ๋ณ์", ์์ง๊ฐ ๋ค์ด๊ฐ์๋ 6๋ฒ line - userId
response.sendRedirect("login.jsp");
}
%>
<!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>
์์ด๋๋ ํจ์ค์๋๊ฐ ํ๋ฆฝ๋๋ค<br/>
<a href="login.jsp">๋ค์ ๋ก๊ทธ์ธ!</a>
</body>
</html>
schedule.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
String id = session.getId(); //์ธ์
๋ชจ์ต ๋ถ๋ฌ์ค๊ธฐ
int sTime = session.getMaxInactiveInterval(); //์ธ์
์๊ฐ
%>
<!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>
์ผ์ ๊ด๋ฆฌ<br/>
์ธ์
ID: <%=id %><br/>
์ธ์
์ ํด์๊ฐ: <%=sTime %>์ด<br/>
</body>
</html>
์ธ์ ๊ธฐ๊ฐ ์ ํด์ฃผ๊ณ ์ถ์ผ๋ฉด -> login.jsp์ ๊ฐ์ : destroy๋ฅผ ์ง๋๊ฒ ๋๋ฉด session์ด ์ญ์ ๋จ


logout.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
session.removeAttribute("userId");//suzi์ญ์
session.invalidate(); //userId ๋ณ์ ์ญ์ - ์ด๊ฒ๋ง ์จ๋๋จ ๊ทธ๋ผ ์์ฐ์ค๋ ๋ณ์๋ ์ญ์ ๋จ
//์ธ์
๋ด์ฉ ๋ณ๊ฒฝ๋์ -> redirect์์ผ์ผํจ (๋ก๊ทธ์ธ์ฐฝ์ผ๋ก ๋์๊ฐ๊ฒ๋)
response.sendRedirect("login.jsp");
%>
โ๏ธ Test4.
โก session์ผ๋ก ๊ฐ์ง๊ณ ์ค๋๋ฒ
โข ๋ฐ์ดํฐ๋ฅผ ๋๊ธฐ๋ 3๊ฐ์ง ๋ฐฉ๋ฒ
:idden์ผ๋ก ์จ๊ฒจ์ ๊ฐ์ง๊ณ ์ค๋ ๋ฒ
- ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋๋ก ๊ฐ์ง๊ณ ์ค๋๊ฑฐ getParameter
: ๊ทธ๋์ hidden์ผ๋ก ์จ๊ฒจ์ ๋ฐ์ดํฐ getParameter๋ก 4๊ฐ ๋ค ์ ๋์ด์ค๊ฒ ํ๊ธฐ
ex1
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
%>
<!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>
<form action="ex2.jsp" method="post">
์ด๋ฆ: <input type="text" name="userName" size="10"/><br/>
์์ผ: <input type="text" name="userBirth" size="10"/><br/>
<input type="submit" value="๋ค์"/><br/>
</form>
</body>
</html>
ex2
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
String userName = request.getParameter("userName");
String userBirth = request.getParameter("userBirth");
//ex1๊บผ๋ฅผ session์ผ๋ก ex3์ ๋์
session.setAttribute("userName", userName);
session.setAttribute("userBirth", userBirth);
%>
<!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>
<form action="ex3.jsp" method="post">
์์ด๋: <input type="text" name="userId" size="10"/><br/>
ํจ์ค์๋: <input type="password" name="userPwd" size="10"/><br/>
<input type="hidden" name="userName" value="<%=userName%>"/>
<input type="hidden" name="userBirth" value="<%=userBirth%>"/>
<input type="submit" value="๊ฐ์
"/><br/>
</form>
</body>
</html>
ex3
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
//String userName = (String)session.getAttribute("userName");
//String userBirth = (String)session.getAttribute("userBirth");
String userName = request.getParameter("userName"); // 2์์ ๋ฐ์์ ์ฃผ์
String userBirth = request.getParameter("userBirth");
String userId = request.getParameter("userId");
String userPwd = request.getParameter("userPwd");
%>
<!--
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
String userName = (String)session.getAttribute("UserName");
String userBirth = (String)session.getAttribute("UserBirth");
//๋์ด์ค๋ ๋ฐ์ดํฐ ์ฒ๋ฆฌ
//String userName = request.getParameter("userName");
//String userBirth = request.getParameter("userBirth");
String userId = request.getParameter("userId");
String userPwd = request.getParameter("userPwd");
%> -->
<!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>
์ด๋ฆ: <%=userName %></br/>
์์ผ: <%=userBirth %></br/>
์์ด๋: <%=userId %></br/>
๋น๋ฐ๋ฒํธ: <%=userPwd %></br/>
</body>
</html>







๊ทธ๋์ ex1 -> ex2๋ก ์ถ๊ฐ์์ ์งํํจ
โ๏ธ Test5.
๐ป ์ ๋ ฅ
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String cp = request.getContextPath();
int n = 0;
String count = (String)application.getAttribute("count");
if(count!=null){
n = Integer.parseInt(count);
}
n++;
application.setAttribute("count", Integer.toString(n));
String realPath = application.getRealPath("/"); //์ ์ผ ์๋จ์ ํ๋ก์ ํธ ์ด๋ฆ ๊ฐ๋ฅดํค๋ ๊ฒ
application.log("์ ์์ฌIP: "+request.getRemoteAddr());
%>
<!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>
์ด ์ ์์ ์ : <%=n %><br/>
์น์๋ฒ ์ค์ ๊ฒฝ๋ก: <%=realPath %>
</body>
</html>
