A few days ago to write the program in the JS file used in the ${pagecontext.request.contextpath} and then always error, there is no way to post to the server, the original JS this as a string, has always thought he is the function of jquery!
${pagecontext.request.contextpath} looks like an El expression! Can only be used in JSP pages!! JS file to get the server name and the program root directory to use the JS comes with the command as follows:
function Getrealpath () {//Gets the current URL, such as: Http://localhost:8083/myproj/view/my.jspvar curwwwpath= window.document.location.href;//get the directory after the host address, such as: Myproj/view/my.jspvar pathname=window.document.location.pathname; var pos=curwwwpath.indexof (pathName);//Get host address, such as: Http://localhost:8083var localhostpaht=curwwwpath.substring (0, POS);//Get the project name with "/", such as:/myprojvar projectname=pathname.substring (0,PATHNAME.SUBSTR (1). IndexOf ('/') +1);//Got Server name and project name Var realpath=localhostpaht+projectname;return realpath;}
Like you set up a project called TEST. This function gets a value of Http://localhost:8080/TEST (that is, the server name + your project name)
Baidu's a lot!! Infringement notice!!
JS (JavaScript) using ${pagecontext.request.contextpath} error