Get the base URL in the JSP page

I showed you how to get the base URL in the Controller of Spring MVC and Spring Boot application. To do this in the JSP page, we will need to use the pageContext object of the Java Servlet.

Roughly speaking about this pageContext object, it is a hidden object of class javax.servlet.jsp.PageContext, used to represent the entire JSP page. We can get the object of the HttpServletRequest class from this pageContext object and from there we will get the base URL information.

Please see the following code snippet:

Very simple, easy to understand, right?

Result:

Get the base URL in the JSP page

Add Comment