今天的积累都是为了更好的明天,加油!我是java程序员,大家可以关注我一起学习哈!
打成war发布tomcat我发现资源路径有问题,有问题咱得解决问题啊!
访问的是返现页面引用的js全部阵亡,均报404,那一定是路径有问题啊!
1.我引入的模板
org.springframework.bootspring-boot-starter-thymeleaf
2.修改application.properties文件 ; 添加: (sliderverificationcode,是对应war打包名)
server.port=8081spring.thymeleaf.mode=LEGACYHTML5spring.thymeleaf.encoding=UTF-8#开发时关闭缓存,不然没法看到实时页面spring.thymeleaf.cache=falseserver.servlet.context-path=/sliderverificationcode
3.html页面,一定要注意引用js的路径问题,我采用的是@{}
滑动验证码
如果不加@{}他就会报404,我们可以看到路径是不对的!
4.ajax请求后端接口,这里注意url前面不要加/ ,因为前置斜杠会覆盖掉我们contextPath该路径
$.ajax({ type: 'POST', url: 'getPic', dataType: 'json', success: function (data) {
url前面不加/,他访问的路径则是http://localhost:8082/sliderverificationcode/getPic这个地址
注意:
#如果Tomcat下部署多个springboot项目,要在 application.properties 添加 , 不然会报错spring.jmx.enabled=false
就此问题就解决了!
今天比较忙就简单写了下,如有问题欢迎留言!