【问题标题】:How to get the project name or path of from context or other class?如何从上下文或其他类中获取项目名称或路径?
【发布时间】:2012-10-15 22:53:29
【问题描述】:

我的项目运行于:

hXXp://localhost:8080/mvc

但是当我在客户端部分重建时,它会是:

hxxp://localhsot:8080/mvc-1.0.0-SNAPSHOT

我想在我的 SpringMVC 控制器之一中获取 mvcmvc-1.0.0-SNAPSHOT 的参数。

(因为我会设置一些动态图片路径)

如何在上下文或控制器类中获取这些名称?

【问题讨论】:

标签: spring servlets spring-mvc path


【解决方案1】:

使用HttpServletRequest.getContextPath():

@RequestMapping
public String handle(HttpServletRequest req) {
    final String context = req.getContextPath();  //mvc or mvc-1.0.0-SNAPSHOT
    //...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多