在WEB-INF中包含javascript文件

Rum*_*mel 4 java jsp struts-1

我正在开发struts的网站.我的文件夹结构如下:

在此输入图像描述

现在,我有一个jsp页面register.jsp,我想在其中添加jquery.validate.js文件.我已按照以下链接提出建议:

不能在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>
Run Code Online (Sandbox Code Playgroud)

上面的代码生成了以下html:

<script type="text/javascript"  src='/LoginApp/WEB-INF/scripts/jquery.validate.js'></script>
Run Code Online (Sandbox Code Playgroud)

jsp文件无法访问javascript文件jquery.validate.js.如何从我的jsp文件中访问它?

此致,Tanvir

Nic*_*tto 5

您应该将文件移到jquery.validate.js外面WEB-INF,webapp/scripts因为它在某种程度上是受保护的目录,因为此目录中的资源默认不公开,然后您将能够使用以下命令访问它:

<script type="text/javascript" src='<c:url value="/scripts/jquery.validate.js"/>'></script>
Run Code Online (Sandbox Code Playgroud)