第一种 设置basePath的方法
要求每个页面中都设置
<%
String path = request.getContextPath();
String basePath =request.getScheme()+"://"+request.getServerName()+":"
+request.getServerPort()+path+"/";
%>
<head>
<base href="<%=basePath%>">
<title>管理员界面</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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<%= path%><br/>
<%= basePath%><br/>
/Web_Servlet_JSP_MySql_Tomcat_Demo
http://localhost:8080/Web_Servlet_JSP_MySql_Tomcat_Demo/
JSP页面:
<div>
<a href="user/normal/servlet/loginOutUser">-注销-</a>
<a href="jsp/modify_password.jsp">-修改密码-</a>
</div>
<div>
<div>
<span style="color:red;font-weight:bold">
<%
if(request.getAttribute("tips")!=null){
out.println(request.getAttribute("tips")+"<br/>");
}
%>
</span>
</div>
<form method="post" action="user/manage/servlet/deleteUser">
....
</form>
第二种 设置basePath的方法
设置一个common.jsp
每个页面都引用这个jsp
common.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="basePath" scope="request">${pageContext.request.contextPath}</c:set>
<%
response.setHeader("Cache-Control","no-catch");
response.setHeader("Pragma","no-catch");
response.setDateHeader("Expires",0);
%>
包含页面:
<%@ include file="/WEB-INF/jsp/global/jsp/common.jsp" %>
使用basePath包含资源:
<script type="text/javascript" src="${basePath}/js/jquery-easyui-1.4.3/jquery.min.js" charset="utf-8"></script>
<script type="text/javascript" src="${basePath}/js/print/jquery.PrintArea.js" charset="utf-8"></script>
<script type="text/javascript" src="${basePath}/js/jquery-easyui-1.4.3/jquery.easyui.min.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="${basePath}/js/jquery-easyui-1.4.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${basePath}/js/jquery-easyui-1.4.3/themes/icon.css" >
<script type="text/javascript" src="${basePath}/js/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js" charset="utf-8"></script>
JQuery
$("#del").click(function(){
var check=[];
$("input[name='handle']:checked").each(function(){
check.push($(this).val());
});
var str=check.toLocaleString();
if(check.length==0){
alert("请选择删除的选项");
return;
}
if(confirm("确定删除选择项吗?")==false)
{
return;
}
$.post("${basePath}/pay/yncConsumer_delConsumer.action",{"ids":str},function(data){
if(data.map=='success'){
location.reload();
}else{
alert("系统错误,删除失败!");
}
},"json");
});