how to get the base url from jsp request object?

前端 未结 6 922
予麋鹿
予麋鹿 2020-11-30 07:10

How to get the base url from the jsp request object? http://localhost:8080/SOMETHING/index.jsp, but I want the part till index.jsp, how is it possible in jsp?

6条回答
  •  一整个雨季
    2020-11-30 07:48

    There is one major flaw in @BalusC accepted answer though. Substring should start from 0 and not 1. Instead of

    
    

    it should be

    
    

    With 1 you get double forward slash: http://localhost:8080//appcontext/ With 0 you get, http://localhost:21080/appcontext/

    In my application, request.getSession(false) always returned null when it was ending in double slash!!!

提交回复
热议问题