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>