Servlet & JSP

path & basePath

<% 
    // 當前頁面 
    String path = request.getContextPath();
    // 項目根目錄
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

head中加入<base href="...">標簽用來表明當前頁面的相對路徑所使用的根路徑。

<head>
  <base href="<%= basePath %>">
</head>

JSTL

jstl標簽不起作用,報錯The tag handler class for "c:if" (org.apache.taglibs.standard.tag.rt.core.IfTag) was not found on the Java Build Path

解決方法:

  • 在jsp頁面開頭加上jstl的taglib
  • 在page標簽中加上屬性isELIgnored="false"
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false" %>

SpringMVC REST風格使用DELETE和PUT METHOD時出現HTTP Status 405 – Method Not Allowed

HTTP Status 405 – Method Not Allowed
Type Status Report
Message JSPs only permit GET POST or HEAD
Description The method received in the request-line is known by the origin server but not supported by the target resource.
Apache Tomcat/9.0.0.M22

原因:JSP 2.3只支持GET POST HEAD請求

解決方法:

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容