JS root directory: Practical tips: Define context root variables in JS application

Source: Internet
Author: User

In Javaweb applications, context is a very important concept, but there is no corresponding concept in JavaScript, and can not be resolved by the URL, so often in the use of Third-party products, encounter a small problem, we can use <% @page contenttype= " Text/javascript "pageencoding=" utf-8 "%> instructions to identify the JSP file as a JS file, in this JSP file to define the context variables for JS call. Here to configure Baidu Ueditor online editor for example.
First, the file path
1, Ueditor path: Context/ueditor
2, root.jsp path: Context/root.jsp
3. Example ue.html: Context/ue.html
Second, the root.jsp file identified as JS file, in this file defined for JS call context variable RootPath
<% @page contenttype= "Text/javascript" pageencoding= "Utf-8"%>
<%
Out.println ("var rootpath = '" + request.getcontextpath () + "';");
%>
Iii. modification of Ueditor editor_config.js documents
The following is the original configuration of Baidu Ueditor in Editor_config.js file
var url= ".                            /"; Here you can configure the Ueditor directory on your site relative path or absolute path
Modified configuration
var url=rootpath+ "/ueditor/";
Iv. Example Ue.html
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
"Http://www.w3.org/TR/html4/loose.dtd" >


<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<title>ueditor Example Www.cxybl.com </title>
<script type= "Text/javascript" charset= "Utf-8" src= "root.jsp" ></script>
<script type= "Text/javascript" charset= "Utf-8" src= "Ueditor/editor_config.js" ></script> this article links http:// Www.cxybl.com/html/wyzz/JavaScript_Ajax/20121102/33574.html

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.