版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_24691413/article/details/78532756
CTX 路径
javascript:void(0)
var $ctx='<%=request.getContextPath()%>'; 定义路径
$("#top_login_form").append($("<a href='"+$ctx+"/NewsListServlet'>管理</a>")); 使用路径
<script type="text/javascript" >
var $ctx='<%=request.getContextPath()%>';
$(function(){ $("#homepagelogin").click(function(){ if($("#user").val() == ""){ alert("用户名不能为空"); return false; } if($("#password").val() == ""){ alert("密码不能为空"); return false; } $.ajax({ "url" : "UserServlet", //要提交的URL路径 "type" : "post", //发送请求的方式 "data" : {user:$("#user").val(),password:$("#password").val()} , //要发送到服务器的数据 "dataType" : "json", //指定返回的数据格式 "success" : function callBack(data) { $("#top_login_form").html("欢迎登录:"+data.userName); var name = data.userName; if(name=="admin"){ alert("哈哈"); $("#top_login_form").append($("<font></font>"));$("#top_login_form").append($("<a href='"+$ctx+"/NewsListServlet'>管理</a>"));
} /* if (data == "true") { $("#nameDiv").html("用户名已被使用!"); } else { $("#nameDiv").html("用户名可以使用!"); } */ }, //响应成功后要执行的代码 "error" : function(msg) { //请求失败后要执行的代码 alert(msg); } }); //end of callBack() }); }); </script>红色的部分是定义路径 蓝色的部分是使用路径.