How to get correct current URL in JSP in Spring webapp

后端 未结 10 582
梦谈多话
梦谈多话 2021-02-03 18:53

I\'m trying to get a correct current URL in JSP in Spring webapp. I\'m trying to use the following fragment in the JSP file:

${pageContext.request.requestURL}
         


        
10条回答
  •  情歌与酒
    2021-02-03 19:41

    Which Spring version are you using? I have tested this with Spring 3.1.1.RELEASE, using the following simple application:

    Folder structure
    -----------------------------------------------------------------------------------
    
    spring-web
        |
         --- src
              |
               --- main
                     |
                      --- webapp
                             |
                              --- page
                             |     |
                             |      --- home.jsp
                             |
                              --- WEB-INF
                                   |
                                    --- web.xml
                                   |
                                    --- applicationContext.xml
    
    home.jsp
    -----------------------------------------------------------------------------------
    
    
    
    
        
            Welcome to Spring Web!
        
        
            Page URL: ${pageContext.request.requestURL}
        
    
    
    web.xml
    -----------------------------------------------------------------------------------
    
    
    
    
    org.example.web
    
    
        spring-mvc-dispatcher
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            /WEB-INF/webContext.xml
        
        1
    
    
    
        spring-mvc-dispatcher
        *.htm
    
    
    
    applicationContext.xml
    -----------------------------------------------------------------------------------
    
    
    
    
    
    
    
    
    
        
        
    
    
    
    

    On accessing http://localhost:8080/spring-web/page/home.jsp, the URL is correctly displayed as http://localhost:8080/spring-web/page/home.jsp.

提交回复
热议问题