The page-relative URL is almost always a fragile way to construct URLs. I always use server-relative URLs that start with the context path. There's no way for the browser to fiddle with those.
If the script is in a js file, you should create a top level variable on the JSP page that captures the context path using the EL. That will make the variable accessible to all loaded script on the page.