今天用ajax验证的时候,ajax的代码一直不起作用,我在浏览器里打开了开发者模式,错误的原因是找不到"jquery-1.8.3.min.js",但是我的目录结构都没有问题。
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
新建的jsp页面开头都会有这样的语句,并且下面还会有一句
<base href="<%=basePath%>">
这些代码的作用是,让你的jsp页面就在项目的根目录下。我做了以下测试:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% 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 'test.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"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <%=basePath%> </body> </html>
其实在myeclipse里,新建的jsp页面,在basePath之后应该接着写,把路径补充完整。比如在上面的测试中,我的就应该加上“innovativePlatform/test/test/”
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/innovativePlatform/test/test/";