본문 바로가기

JSP(Java Server Page)

JSP 정보 확인하는 메소드

info.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>


<!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>


<a href="request_info.jsp">request 정보확인</a><br/>



</body>

</html>


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


request_info.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%

String ip=request.getRemoteAddr(); 

String cp=request.getContextPath();

String uri=request.getRequestURI();

StringBuffer url=request.getRequestURL();

String protocol = request.getProtocol();

String sname=request.getServerName();

int sport=request.getServerPort();

String method=request.getMethod();

String path=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();


//이전 주소

String referer=request.getHeader("Referer");

if(referer==null)

referer="주소치고 들왓다";

//클라이언트 브라우져

String user=request.getHeader("User-Agent");

if(user.indexOf("MSIE")!=-1) {

out.print("<script>alert('익스플로러 사용중...');</script>");

}else if(user.indexOf("Chrome")!=-1){

out.print("<script>alert('크롬 사용중...');<script>");

}


%>

<!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>


클라이언트 IP 주소 : <%=ip %><br/>

cp:<%=cp %><br/>

uri:<%=uri%><br/>

url:<%=url%><br/>


프로토콜 : <%=protocol %><br/>

serverName : <%=sname%><br/>

sercerPort : <%=sport %><br/>

method : <%=method %><br/>

path : <%=path %><br/>

이전주소 : <%=referer %><br/>

User-Agent :<%=user %><br/>


<a href="info.jsp">되돌아가기</a><br/>

<a href="javascript:history.back();">되돌아가기</a><br/>


</body>

</html>