I am developing a website in struts. My folder structure is as follows :
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 :
Can not include javascript file from WEB-INF directory in JSP.
My code was as follows :
<%@ 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>
The above code generated the following html :
<script type="text/javascript" src='/LoginApp/WEB-INF/scripts/jquery.validate.js'></script>
The jsp file could not access the javascript file jquery.validate.js. How can I access it from my jsp file ?
Regards, Tanvir
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>