You should be aware that javascript runs on client side and jsp-code on server side.
You can only pass results (strings, numbers), calculated from impicit objects, to the client, but you cannot pass serverside objects directly or manipulate them. These results can be calulations from implicit objects as you have shown in your code.
therefore you don't pass the implicit object "request", but you can pass a string that its method getContextpath produces. With this knowledge you should be aware that you have to use quotation marks here. So to make it working, you should correct your code to
- var path = "<%=request.getContextPath()%>";
By the way:
There is only one way of accessing/manipulating objects on the server from the clientside javascript :
Ajax.
But again, not directly, but manipulating them in an indirect way.