jsp里面不能使用${pageContext.request.contextPath}解決方案


1.在jsp中使用${pageContext.request.contextPath}獲取相對路徑,可是最后路徑變為:http://localhost:8080/oneself/$%7BpageContext.request.contextPath%7D/css/reset.css
2.貼圖,這是瀏覽器的調試頁面,可以看到獲取css的路徑帶上了${pageContext.request.contextPath},而console中打印的獲取css地址為$%7BpageContext.request.contextPath%7D,並不清楚什么原因,希望各位大佬指點。
圖片描述

login.jsp頁面

 
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Login</title> <!-- CSS --> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/reset.css"> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/supersized.css"> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css"> <!-- Javascript --> <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js" ></script> <script type="text/javascript" src="${pageContext.request.contextPath}/js/supersized.3.2.7.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/js/supersized-init.js"></script> <!-- HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <!--<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>--> <!--[endif]--> </head> <body oncontextmenu="return false"> <div class="page-container"> <div id="log-box"> <h1>登 錄</h1> <form action="${pageContext.request.contextPath}/user/login.do" method="post"> <table> <tr> <td class="log-reg"> <div> <input type="text" id="username" name="username" class="username" placeholder="用戶名/郵箱名" autocomplete="off" onblur="validname()" /> </div></td> <td class="errmsg"><span style="overflow: hidden;" id="errorMsgname" /> </td> </tr> <tr> <td class="log-reg"> <div> <input id="password" type="password" name="password" class="password" placeholder="密碼" oncontextmenu="return false" onpaste="return false" onblur="validpwd()" /> </div> <td class="errmsg"><span style="overflow: hidden;" id="errorMsgpwd" /> </td> </tr> <tr> <td colspan="2" class="btn-left"><input type="submit" class="btn" id="submit" value="登 錄" /> </td> </tr> <tr> <td colspan="2" class="btm-left"> <p class="box-button"> 沒有賬號,先 <a href="${pageContext.request.contextPath}/user/showregister.do">注冊</a> </p> </td> </tr> <tr> <td colspan="2" class="btm-pa"> <p class="box-button" id="btm-p"> <a href="#">忘記密碼?</a> </p> </td> </tr> </table> </form> </div> <div class="connect"> <p>If we can only encounter each other rather than stay with each other,then I wish we had never encountered.</p> <p style="margin-top:20px;">如果只是遇見,不能停留,不如不遇見。</p> </div> </div> <div class="alert" style="display:none"> <h2>消息</h2> <div class="alert_con"> <p id="ts"></p> <p style="line-height:70px"> <a class="btn">確定</a> </p> </div> </div> <script type="text/javascript"> $(".btn").click(function() { is_hide(); }); $("#submit").live('click', function() { var u = $("#username"); var p = $("#password"); if (u.val() == '' || p.val() == '') { $("#ts").html("用戶名或密碼不能為空~"); is_show(); return false; } else { var reg = /^[0-9A-Za-z]+$/; if (!reg.exec(u.val())) { $("#ts").html("用戶名錯誤"); is_show(); return false; } } }); window.onload = function() { $(".connect p").eq(0).animate({ "left" : "0%" }, 600); $(".connect p").eq(1).animate({ "left" : "0%" }, 400); }; function is_hide() { $(".alert").animate({ "top" : "-40%" }, 300); } function is_show() { $(".alert").show().animate({ "top" : "45%" }, 300); }; function validname() { var val = $("#username").val(); if (val == '' || $.trim(val) == '') { $("#errorMsgname").html('用戶名不能為空'); $("#errorMsgname").show(); } else { $.ajax({ type: "post", url: "finduserisnull.do?info=" + val, data: "", success: function(data) { if(data=="false"){ $("#errorMsgemail").html('用戶未注冊!'); }else { $("#errorMsgemail").html('<img src="img/yes.jpg" style="width: 18px;height: 18px;"/>'); }} }); } }; function validpwd() { //獲取id為password對應的input輸入框中的值 var val = $("#password").val(); if (val == '' || $.trim(val) == '') { //如果val為空或者空格,將錯誤消息顯示在對應span $("#errorMsgpwd").html('密碼不能為空'); //讓span顯示出來 $("#errorMsgpwd").show(); } else { $("#errorMsgpwd").html('<img src="${pageContext.request.contextPath}/img/yes.jpg" style="width: 18px;height: 18px;"/>'); } }; </script> </body> </html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM