RadarURL
웹 프로그래밍

JSP에서 URL, IP 알아내기

by JaeSoo posted Jun 24, 2007
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

-- IP 알아내기


<%@ page import="java.net.InetAddress" %>


 String Addr=request.getRemoteAddr(); // 로컬 ip
 String Host=request.getRemoteHost(); // 로컬 ip
 int Port=request.getServerPort(); // 서버 port
 
 out.println(Addr);
 out.println(Host);
 out.println(Port);


 


<% InetAddress inet= InetAddress.getLocalHost(); %>
server ip: <%=inet.getHostAddress()%>


 


 


-- 서버의 기본 경로
<%=application.getRealPath("/")%>
<%=request.getRealPath("/")%>


 


 


-- URL  알아내기


<%@ page contentType="text/html; charset=euc-kr" %>
Context : <%= request.getContextPath() %>   -> Context : /examples
URL : <%= request.getRequestURL() %>       -> URL : http://localhost/examples/test.jsp
URI : <%= request.getRequestURI() %>         -> URI : /examples/test1.jsp
Path : <%= request.getServletPath() %>        -> Path : /test1.jsp


출처 : http://cafe.naver.com/fieldday/17


Articles

1 2 3 4 5 6 7 8 9 10