各位大师,你们好:
最近碰到一个问题
springboot工程使用内置测试(内置tomcat9.0.60)时,网址路径不区分大小写, 但是打包war后部署,放在外置tomcat9.0.60(版本和内置tomcat相同),网址路径却区分大小写。 比如/external/main.html在浏览器中写成/external/Main.html就404.
我在外置tomcat的server.xml已经设置了context节中 caseSensitive="false"但是无效。
想知道:
谢谢各位!!
通常来讲,页面还是区分大小写,以小写字母作为文件的文件名。
回答:似乎被禁用了,为了安全性,不过我没有具体实验;我觉得你可以对请求进行解析,即添加拦截器对请求路径进行统一小写之后再转发给控制器,这样可以安全一些;可以参考这篇文章说明 caseSensitive="false" 的无效性 https://blog.csdn.net/xinlanzero/article/details/83669773
然后springboot的路径大小写设置,简单加一个 Config 类即可
package com.redirect.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
/**
* @author bbyh
* @date 2022/11/23 0023 14:41
* @description
*/
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
@Override
public void configurePathMatch(PathMatchConfigurer config) {
AntPathMatcher matcher = new AntPathMatcher();
matcher.setCaseSensitive(false);
config.setPathMatcher(matcher);
}
}
补充内容:
同样tomcat版本, jar打包不区分大小写, war打包就区分大小写。 这其中应该有一个设置或配置。