标签:login car ase request ext XML toc pos ref
jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="<%=basePath%>/css/mycss/login_css.css" rel="stylesheet" type="text/css" />
</head>
js:
方法一
function getRealPath(){
//获取当前网址,如: http://localhost:8083/myproj/view/my.jsp
var curWwwPath=window.document.location.href;
//获取主机地址之后的目录,如: myproj/view/my.jsp
var pathName=window.document.location.pathname;
var pos=curWwwPath.indexOf(pathName);
//获取主机地址,如: http://localhost:8083
var localhostPaht=curWwwPath.substring(0,pos);
//获取带"/"的项目名,如:/myproj
var projectName=pathName.substring(0,pathName.substr(1).indexOf(‘/‘)+1);
//得到了 http://localhost:8083/myproj
var realPath=localhostPaht+projectName;
alert(realPath);
}
方法二:
function getRootPath_dc() { var pathName = window.location.pathname.substring(1); var webName = pathName == ‘‘ ? ‘‘ : pathName.substring(0, pathName.indexOf(‘/‘)); if (webName == "") { return window.location.protocol + ‘//‘ + window.location.host; } else { return window.location.protocol + ‘//‘ + window.location.host + ‘/‘ + webName; }}
常识补充:
标签:login car ase request ext XML toc pos ref
原文地址:http://www.cnblogs.com/haimishasha/p/6209413.html