inc.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("basePath",basePath);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'inc.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="${basePath}/js/jquery-1.8.2.js"></script>
<script type="text/javascript">
var jspath=getRootPath();
//获取项目根路径
function getRootPath(){
//获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp
var curWwwPath=window.document.location.href;
//获取主机地址之后的目录,如: uimcardprj/share/meun.jsp
var pathName=window.document.location.pathname;
var pos=curWwwPath.indexOf(pathName);
//获取主机地址,如: http://localhost:8083
var localhostPaht=curWwwPath.substring(0,pos);
//获取带"/"的项目名,如:/uimcardprj
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
return(localhostPaht+projectName);
}
</script>
</head>
</html>
index.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<jsp:include page="../layout/inc.jsp" />
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
function doMenu(param){
var iframe=document.getElementById("centerframe");
if(param==1){
iframe.src=jspath+"/layout/a1.jsp";
}else if(param==2){
iframe.src=jspath+"/layout/a2.jsp";
}
}
</script>
</head>
<frameset rows="50,*,40">
<frame id="topframe" name="topframe" src="${basePath}/layout/top.jsp">
<frame id="centerframe" name="centerframe" src="${basePath}/layout/center.jsp">
<frame id="bottomframe" name="bottomframe" src="${basePath}/layout/bottom.jsp">
</frameset>
</html>
center.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<jsp:include page="../layout/inc.jsp" />
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'center.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
//链接
function doLink(param){
var iframe=document.getElementById("mainframe");
$.ajax({
type: "POST",
dataType: "json",
url: jspath+param,
success: function(data) {
alert(data);
iframe.src=jspath+data;
}
});
}
</script>
</head>
<frameset cols="30%,70%">
<frame id="leftframe" name="leftframe" src="${basePath}/layout/left.jsp">
<frame id="mainframe" name="mainframe" src="${basePath}/layout/main.jsp">
</frameset>
</html>
/**
* @author chenzheng
* @since 2013-8-25
* @Description: 链接一
* @throws
* @return
* @throws Exception
* String
*/
public String doLink1Action() throws Exception {
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
PrintWriter pw = null;
try {
pw = response.getWriter();
pw.write("/layout/a1.jsp");
} catch (IOException e) {
e.printStackTrace();
}
pw.flush();
pw.close();
return null;
}
/**
* @author chenzheng
* @since 2013-8-25
* @Description: 链接二
* @throws
* @return
* @throws Exception
* String
*/
public String doLink2Action() throws Exception {
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
PrintWriter pw = null;
try {
pw = response.getWriter();
pw.write("/layout/a2.jsp");
} catch (IOException e) {
e.printStackTrace();
}
pw.flush();
pw.close();
return null;
}
效果图: