There are several needs to access context root in various places of your application.
Various ways are,
In Jspx: ${pageContext.request.contextPath}
In servlet:
public static String getContextpath(HttpServletRequest request) {
return request != null ? request.getContextPath() : null;
}
In bean:
public static String getContextpath() {
ExternalContext extContext= FacesContext.getCurrentInstance().getExternalContext();
String url = extContext.getRequestContextPath();
return url;
}
In Javascript:
function getContextPath(){
return window.location.pathname.substring(0,window.location.pathname.indexOf("/",2));
}
In CSS: background: url(../resources/images/header.jpg")
Kotlin : Android App Development Choice
ReplyDeleteBest AI Startups In India
Web Robots
Tags Added in HTML5
MariaDB vs MySQL
Most in demand programming languages
Data Science Life Cycle
Features of R Programming Language
Data Science in Real Life
Most in demand NoSQL databases software