Retrieving the servlet context path from a Spring web application

If you use a ServletContainer >= 2.5 you can use the following code to get the ContextPath: import javax.servlet.ServletContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component @Component public class SpringBean { @Autowired private ServletContext servletContext; @PostConstruct public void showIt() { System.out.println(servletContext.getContextPath()); } }

How to use relative paths without including the context root name?

If your actual concern is the dynamicness of the webapp context (the “AppName” part), then just retrieve it dynamically by HttpServletRequest#getContextPath(). <head> <link rel=”stylesheet” href=”https://stackoverflow.com/questions/4764405/${pageContext.request.contextPath}/templates/style/main.css” /> <script src=”${pageContext.request.contextPath}/templates/js/main.js”></script> <script>var base = “${pageContext.request.contextPath}”;</script> </head> <body> <a href=”${pageContext.request.contextPath}/pages/foo.jsp”>link</a> </body> If you want to set a base path for all relative links so that you don’t need to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)