jquery绝对路径

<strong>1、修改为绝对路径</strong>
$(document).ready(function(){
    	
    	
    	$.get("${pageContext.request.contextPath}/servlet/Test",null,
            function (data) {
    			alert("hello");
                $("#logs").append("[data: " + data + " ]<br/>");
        });
        
    	
    });
${pageContext.request.contextPath}

相当于得到项目名称,等价于<%=request.getContextPath()%>

我的项目名称是weibo_web_tool_ajax  得到的为/weibo_web_tool_ajax

注意:

${pageContext.request.contextPath}

是el表达式,只能写在jsp中,不能写在js中

2、直接用 servlet/DataServlet


如果用

/servlet/Test
相当于http://localhost:808/servlet/Test



原文地址:https://www.cnblogs.com/yan456jie/p/5369452.html