0

I am currently using Spring and AngularJS.

So far no problem displaying my index.html using Spring like so

@RequestMapping(value="/")
public String index() {
    return "/app/index.html";
}

Is there any way I can get my context path in my .html? Or should I render my index as index.jsp?

1 Answer 1

3

As you said, you should render it as a JSP in order to access the contextpath:

${pageContext.request.contextPath}

If you wanna stick to pure HTML maybe you could extract it from the URL with Javascript:

function getContextPath() {
    return window.location.pathname.substring(0, window.location.pathname.indexOf("/",2));
}
console.log(getContextPath());
Sign up to request clarification or add additional context in comments.

3 Comments

Yeah I'm hoping for other options though if they exist.
The JS alternative will do for now. Thanks!
Is there an easy way to append the result of getContextPath() to a href link?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.