language="java"
contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.net.URLEncoder" %>
<%@page import="java.net.URLDecoder"%>
<html>
<body>
<font face=Arial>
<b><u>Implicit Object - Request</u></b><br>
<br>
<u>매개 변수</u>
<br>
<form method=POST action="?" >
ID : <br>
<input type=text size=20 name=ID value=""><br>
Name : <br>
<input type=text size=20 name=NAME value=""><br>
Language :<br>
<input type=checkbox name=L value=JSP> JSP
<input type=checkbox name=L value=Perl> Perl
<input type=checkbox name=L value=PHP> PHP
<br>
<input type=submit value="확인">
</form>
<%
try{
for (java.util.Enumeration e = request.getParameterNames() ; e.hasMoreElements() ;) {
String name = e.nextElement().toString();
out.println(name + ":"+request.getParameter(name)+"<br>");
}
String lan[] = request.getParameterValues("L");
for(int i = 0;i < lan.length;i++){
if( i < lan.length-1 ) out.println(lan[i]+";");
else out.println(lan[i]+"<br>");
}
}catch(Exception e){
out.println("아직 파라미터를 전송받지 못했습니다.");
}
%>
</font>
<br>
<hr>
<br>
<br>
<font face=Arial>
<b><u>Implicit Object - Request ( Cookie Setting )</u></b><br>
<%
try{
String Nom = URLEncoder.encode("홍완이");
Cookie c1 = new Cookie("ID","ngio");
Cookie c2 = new Cookie("NAME",Nom);
response.addCookie(c1);
response.addCookie(c2);
Cookie[] cookies = request.getCookies(); // 쿠키 배열에 쿠키값 가져오기
out.println( cookies.length + " 개의 쿠키가 존재합니다.<br><br>");
for( int i = 0; i < cookies.length; i++ ){
Cookie thisCookie = cookies[i];
out.println(thisCookie.getName() + " => " );
out.println(URLDecoder.decode(thisCookie.getValue(),"euc-kr") + "<br>" );
}
}catch(Exception e){
out.println("쿠키가 생성되지 않았습니다.");
}
%>
</font>
<br>
<hr>
<br>
<br>
<u>환경 변수</u>
<br>
<%
out.println("Method : " + request.getMethod()+"<br>");
out.println("QueryString : " + request.getQueryString()+"<br>");
out.println("RemoteAddr : " + request.getRemoteAddr()+"<br>");
out.println("RequestURI : " + request.getRequestURI()+"<br>");
out.println("ServletPath : " + request.getServletPath()+"<br>");
out.println("ContentType : " + request.getContentType()+"<br>");
out.println("ContentLength : " + request.getContentLength()+"<br>");
out.println("CharacterEncoding : " + request.getCharacterEncoding()+"<br>");
%>
</body>
</html>
Posted by 홍반장