Springboot怎么添加server.servlet.context-path

发布时间:2023-03-01 17:28:31 作者:iii
来源:亿速云 阅读:146

本篇内容介绍了“Springboot怎么添加server.servlet.context-path”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

Springboot添加server.servlet.context-path

server.servlet.context-path配置的作用

定义: server.servlet.context-path= # Context path of the application. 应用的上下文路径,也可以称为项目路径,是构成url地址的一部分。

springboot 2.0变革后的配置区别

1、springboot 2.0之前,配置为 server.context-path

2、springboot 2.0之后,配置为 server.servlet.context-path

一个思考

原来的运营项目(已上线),配置文件添加 server.servlet.context-path 配置后,需要在thymleaf 中进行action请求的追加吗?

答案:不需要。

栗子:

前端页面采取form请求

<form th:action="@{/user/userLogin}" method="post" id="userLogin"></form>

action拦截接受方式

@Controller
@RequestMapping("/user")
public class LoginController {
 
@PostMapping("/userLogin")
public String userLogin(HttpServletRequest request, Model model) {

原项目的基础上,追加一个配置

server:  port: 8080  servlet:    context-path: /demo

只需要再开始进入首页时,追加 localhost:8080/demo ,后续的thymleaf中的href和action等无需添加/demo 。

Springboot配置 server.servlet-path 和 server.context-path

server.context-path

设定应用的context-path.

根据 springboot版本context-path不同

server.servlet-path

示例

小拓展:

1.只配置了server.servlet-path = /demo,访问路径是http://ip:port/demo/...

2.如果使用的idea,只在Tomcat配置了 Application context了,访问路径是http://ip:port/test/...

3.如果使用的idea,已经在Tomcat配置了 Application context了(下图),也配置了server.servlet-path = /demo,访问路径是http://ip:port/test/demo/...

Springboot怎么添加server.servlet.context-path

“Springboot怎么添加server.servlet.context-path”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. 怎么在Spring Boot 中通过AOP和自定义注解实现权限控制
  2. Spring Boot2构建可部署的war包

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springboot server.servlet.context-path

上一篇:MySQL怎么按天分组统计一定时间内的数据

下一篇:MySQL8.0.32的安装与配置的方法是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》