JS (JavaScript) using ${pagecontext.request.contextpath} error

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.