1. 디자인 소스 코드
코드 사본은 다음과 같습니다.
<%@ page language = "java"import = "java.util.*"pageencoding = "utf-8"%>
<! doctype html public "-// w3c // dtd html 4.01 Transitional // en">
<html>
<헤드>
<title> javaScript get path </title>
<meta http-equiv = "pragma"content = "no-cache">
<meta http-equiv = "캐시 제어"content = "no-cache">
<meta http-equiv = "만료"내용 = "0">
<meta http-equiv = "keywords"content = "keyword1, keyword2, keyword3">
<meta http-equiv = "description"content = "이것은 내 페이지입니다">
<script type = "text/javaScript">
함수 findPath ()
{
// 현재 URL을 가져옵니다
var curnetaddr = window.document.location.href;
경고 ( "현재 URL 받기 :" + CurnetAddr);
// 호스트 주소 다음에 디렉토리를 가져옵니다
var hostpath = window.document.location.pathname;
ALERT ( "호스트 주소 다음에 디렉토리 가져 오기 :" + hostPath);
// 문자열에서 지정된 문자열 값의 첫 번째 발생을 반환합니다.
var count = curnetaddr.indexof (hostpath);
ALERT ( "지정된 문자열 값이 먼저 문자열에 나타나는 위치를 반환합니다." + count);
// 호스트 주소를 가져옵니다
var hostaddr = curnetaddr.substring (0, count);
ALERT ( "호스트 주소 얻기 :" + hostAddr);
// "/"로 프로젝트 이름을 얻습니다.
var projectName = hostPath.SubString (0, hostPath.substr (1) .indexof ( '/')+1);
ALERT ( ""/"로 프로젝트 이름 가져 오기 :" + projectName);
// 프로젝트 경로를 얻습니다
var path = hostaddr + projectname;
경고 ( "프로젝트 경로 얻기 :" + 경로);
}
</스크립트>
</head>
<body>
<div id = "body_div">
<입력 유형 = "button"id = "btn"value = "get path"onclick = "findpath ()"/>
</div>
</body>
</html>
2. 디자인 결과
(1) 초기화
(2) 현재 URL을 받으십시오
(3) 호스트 주소 후에 디렉토리를 얻습니다
(4) 지정된 문자열 값이 문자열에 먼저 나타나는 위치를 반환합니다.
(5) 호스트 주소를 얻습니다
(6) "/"로 프로젝트 이름을 얻으십시오.
(7) 프로젝트 경로를 얻으십시오