java - 从 WEB-INF 中包含 javascript 文件

标签 java jsp struts-1

<分区>

我正在用 struts 开发一个网站。我的文件夹结构如下:

enter image description here

现在,我有一个 jsp 页面 register.jsp,我想在其中添加 jquery.validate.js 文件。我遵循了以下链接的建议:

Can not include javascript file from WEB-INF directory in JSP.

我的代码如下:

<%@ 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:

<script type="text/javascript"  src='/LoginApp/WEB-INF/scripts/jquery.validate.js'></script>

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

问候, 坦维尔

最佳答案

您应该将文件 jquery.validate.js 移到 webapp/scripts 中的 WEB-INF 之外,因为它在某种程度上是 protected 目录,因为此目录中的资源默认情况下是非公共(public)的,那么您将能够使用以下方式访问它:

<script type="text/javascript" src='<c:url value="/scripts/jquery.validate.js"/>'></script>

关于java - 从 WEB-INF 中包含 javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39766914/

相关文章:

java - 是否有可能停止 REST 调用?

java - Mapview 顶部的另一个片段(SupportMapFragment)

java - 列表中每个对象的表单 - ThymeLeaf

java - 在 JSP 中 Autowiring Spring Beans 的最干净的方法是什么?

java - Struts 1(已停产)可以与 Java EE7 一起使用吗?

java - 从数据库中检索数据并用单选按钮显示它,单选按钮包含 struts 1.2 中的数据值

java - 将 jpanel 清除为透明

java - 无法找到 'struts.multipart.saveDir' 属性设置。默认为 javax.servlet.context.tempdir

java - 无法从字符串转换为整数