SpringSource IDE does not use project name as root URL for Spring MVC application

后端 未结 3 921
旧时难觅i
旧时难觅i 2021-01-02 19:34

When I create a Spring MVC Template Project with the SpringSource IDE, I run the application and the root URL is set as the last word of the default package name:

Fo

3条回答
  •  無奈伤痛
    2021-01-02 20:10

    The first part in the URL after host and port is called the context-path. In your case myapp. In tomcat the context-path is equal to the name of the war-file. If you name the war-file ROOT.war then no context-path is used.

    As bimsapi mentioned you can change the context-path in STS, too.

    But: You can and should make your app independent of the context-path. If you are using JSP then build links with the tag:

    
    

    This outputs the correct url including the actual context-path. Or your can store it in a variable and use it later:

    
    Cancel
    

    In Java code you can get the context-path with:

    request.getContextPath()
    

    where request is the current HttpServletRequest object. Using this makes your app completely independent of the actual context-path which simplifies deployment a lot.

提交回复
热议问题