在WEB-INF中包含javascript文件 [英] Include javascript file from inside WEB-INF
问题描述
我正在开发一个struts网站。我的文件夹结构如下:
I am developing a website in struts. My folder structure is as follows :
现在,我有一个jsp页面register.jsp,我想在其中添加jquery.validate.js文件。我已按照以下链接提出建议:
Now, I have a jsp page register.jsp, in which I want to add jquery.validate.js file. I have followed suggestion from the following link :
不能在JSP中包含WEB-INF目录中的javascript文件。
我的代码是如下:
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Insert title here</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://use.fontawesome.com/0c2573c7d6.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src='<c:url value="/WEB-INF/scripts/jquery.validate.js"/>'></script>
以上代码生成以下html:
The above code generated the following html :
<script type="text/javascript" src='/LoginApp/WEB-INF/scripts/jquery.validate.js'></script>
jsp文件无法访问javascript文件jquery.validate.js。如何从我的jsp文件中访问它?
The jsp file could not access the javascript file jquery.validate.js. How can I access it from my jsp file ?
问候,
Tanvir
Regards, Tanvir
推荐答案
您应该在<$ WEB-INF
之外移动文件 jquery.validate.js
c $ c> webapp / scripts 因为它在某种程度上是受保护的目录,因为此目录中的资源默认不公开,那么您将能够使用以下方式访问它:
You should move your file jquery.validate.js
outside WEB-INF
in webapp/scripts
as it is somehow a protected directory since resources inside this directory are by default non public, then you will be able to access it using:
<script type="text/javascript" src='<c:url value="/scripts/jquery.validate.js"/>'></script>
这篇关于在WEB-INF中包含javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!