Servlet & JSP

path & basePath

<% 
    // 当前页面 
    String path = request.getContextPath();
    // 项目根目录
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

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请求

解决方法:

  • 简单解决方法,在被请求的页面<%@ page %>中添加<%@ page isErrorPage="true" %>
  • 详细信息参看 stackoverflow - HTTP Status 405 - JSPs only permit GET POST or HEAD

你可能感兴趣的:(Servlet & JSP)