Jqueryjs is an effective solution for loading JS files in jQuery JSP.

Source: Internet
Author: User

Jqueryjs is an effective solution for loading JS files in jQuery JSP.
Effective Solution for loading JS files by JSP: Font: [Increase or decrease] type: Reprinted time: JSPs importing jquery files, always does not work, the reason is that it cannot access/WEB-INF/directory files, the following has a good solution, you can refer to the next

Directory structure: jsp imports jquery files, which always does not work because:

Copy the Code as follows:
<Script type = "text/javascript" src = "js/jquery-1.4.2.min.js"> </script>


It cannot access the files under the/WEB-INF/directory, so it is necessary to put the loaded js file into the webapp directory.
 
Test.html:

Copy the Code as follows:


<% @ Page language = "java" %>
<% @ Page contentType = "text/html; charset = UTF-8" %>
<% @ Page import = "java. util. *" %>
<% @ Page isELIgnored = "false" %>

<% @ Taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<% @ Taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>

<%
String path = request. getContextPath ();
String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
%>

<Html>
<Head>
<Base href = "<% = basePath %>"/>
<Link rel = stylesheet type = "text/css" href = "css/style.css"/>
<Script type = "text/javascript" src = "js/jquery-1.5.1.min.js"> </script>

<Script type = "text/javascript">
$ (Document). ready (function (){
Alert ("hello, jquery ");
});
</Script>

<Title> logon </title>
</Head>

<Body>
<P class = "error"> <% = basePath %> </p>
</Body>
</Html>

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.