세션 메소드
리턴 메소드 설명
httpSession getSession

요청한 클라이언트에 할당된 HttpSession 객체를 반환.

없다면 새로운 객체 생성

HttpSession getSession(Boolean create)

create 가 true 이면 getSession() 메소드와 동일한 결과를 리턴.

create 가 false로 지정하면 이전에 생성된 HttpSession 객체가 없을 경우 null을 리턴

String getRequestedSessionId() 요청한 클라이언트에 지정된 세선의 ID를 문자열로 리턴한다.
boolean isRequestedSessionIdValid() 요청에 포함된 클라이언트의 세션ID가 유효하면 true 아니면 false 리턴
쿠키, URL/URI, 요청 방식 관련 메소드

리턴 메소드 설명
Cookie[] getCookies() Http 요청 메세지의 헤더에 포함된 쿠키를 javax.servlet.http.Cookie 배열로 리턴
String getServerName() 서버의 도메인명을 문자열로 리턴
int getServerPort() 서버의 포트번호를 int형으로 리턴
StringBuffer getRequestURL() 요청 URL을 StringBuffer로 리턴
String getRequestURI() 요청URI를 문자열로 리턴
String getQueryString() 요청에 사용된 쿼리 문장을 문자열로 리턴
String getRemoteHost() 클라이언트의 호스트 이름을 문자열로 리턴
String getRemoteAddr() 클라이언트 IP주소를 문자열로 리턴
String getProtocol() 요청에 사용된 프로토콜 이름을 문자열로 리턴
String getMethod() 요청에 사용된 요청 방식(Get,Post)를 문자열로 리턴
String getContextPath() 해당 JSP 페이지의 컨텍스트 경로를 문자열로 리턴
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Request Test3</title>
<style type="text/css">
h1
{
	text-align : center;
}
table
{
	margin : auto;
	width : 400px;
	border : 1px solid red;
}
</style>
</head>
<body>
	<h1>쿠키, URL/URI, 요청방식에 관련된 정보 예제</h1>
	<table border = "1">
		<tr>
			<td>쿠키 정보</td>
		<%
		Cookie[] cookie = request.getCookies();
		if(cookie == null)
		{
		    %>
		    <td>쿠키가 존재하지 않습니다</td>
		<%
		}
		else
		{
		    for(int i = 0; i < cookie.length; i++)
		    {
		        %>
		        <td><%=cookie[i].getName() %>
		        <%=cookie[i].getValue() %>) &nbsp;&nbsp;
		        </td>
		        <% 
		    }
		}
		%>
			</tr>
			<tr>
				<td>서버 도메인명</td>
				<td><%=request.getServerName() %>
			</tr>
			
			<tr>
				<td>서버 포트번호</td>
				<td><%=request.getServerPort() %>
			</tr>
			
			<tr>
				<td>요청 URL </td>
				<td><%=request.getRequestURL() %>
			</tr>
			
			<tr>
				<td>요청 URI</td>
				<td><%=request.getRequestURI() %>
			</tr>
			
			<tr>
				<td>요청 쿼리</td>
				<td><%=request.getQueryString() %>
			</tr>
			
			<tr>
				<td>클라이언트 호스트명</td>
				<td><%=request.getRemoteHost() %>
			</tr>
			
			<tr>
				<td>클라이언트 IP 주소</td>
				<td><%=request.getProtocol() %>
			</tr>
			
			<tr>
				<td>프로토콜</td>
				<td><%=request.getProtocol() %>
			</tr>
			
			<tr>
				<td>요청 방식</td>
				<td><%=request.getMethod() %></td>
			</tr>
			
			<tr>
				<td>컨텍스트 경로</td>
				<td><%=request.getContextPath() %></td>
			</tr>
	</table>
</body>
</html>

 

'JSP' 카테고리의 다른 글

[JSP] Session 객체  (0) 2019.11.02
[JSP] pageContext 객체  (0) 2019.11.02
[JSP] 내장객체 - http헤더  (0) 2019.11.02
[JSP] 내장 객체 - request  (0) 2019.11.02
[JSP] 서블릿 페이지-> JSP페이지/ JSP 스크립트 요소  (0) 2019.10.30