java - JSP doesn't see CSS and JS files from resources folder -
i have problem css , js import in web application. using servlets/jsp/css/js.
i sorry question, saw many questions , answers theme , situation nothing helped me.
i trying add css , js files this:
<link rel="stylesheet" href="<c:url value='/resources/stylesheet/common.css' />"/> <link rel="stylesheet" href="<c:url value='/resources/stylesheet/index.css' />"/> <script type="text/javascript" src="resources/js/validators/loginvalidator.js"></script>
but happends , of css , js files doesn't work. folders/files positions in project:
i had tried many different ways terminate issue. tried this: https://stackoverflow.com/a/23687360/5331196 , https://stackoverflow.com/a/29012643/5331196
and nothing helped me. thing working dinamyc import: <%@include file="/resources/stylesheet/login.css" %>
e.t.c.
it helped, but, in case, there lot of code in jsp page because .css , .js files huge.
what should terminate issue , how can static import in situation?
thanks all,who can answer, friend, davakin111.
my web.xml file:
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <display-name>jean taxi-service</display-name> <listener> <listener-class>com.taxi.service.utils.applicationcontext</listener-class> </listener> <filter> <filter-name>clientfilter</filter-name> <filter-class>com.taxi.service.filter.clientfilter</filter-class> </filter> <filter-mapping> <filter-name>clientfilter</filter-name> <url-pattern>/someurl1</url-pattern> </filter-mapping> <filter> <filter-name>orderfilter</filter-name> <filter-class>com.taxi.service.filter.orderfilter</filter-class> </filter> <filter-mapping> <filter-name>orderfilter</filter-name> <url-pattern>/someurl2</url-pattern> </filter-mapping> <servlet> <servlet-name>initcontroller</servlet-name> <servlet-class>com.taxi.service.controller.initcontroller</servlet-class> </servlet> <servlet> <servlet-name>logincontroller</servlet-name> <servlet-class>com.taxi.service.controller.logincontroller</servlet-class> </servlet> <servlet> <servlet-name>registrationcontroller</servlet-name> <servlet-class>com.taxi.service.controller.registrationcontroller</servlet-class> </servlet> <servlet> <servlet-name>usercontroller</servlet-name> <servlet-class>com.taxi.service.controller.usercontroller</servlet-class> </servlet> <servlet> <servlet-name>ordercontroller</servlet-name> <servlet-class>com.taxi.service.controller.ordercontroller</servlet-class> </servlet> <servlet> <servlet-name>privateareacontroller</servlet-name> <servlet-class>com.taxi.service.controller.privateareacontroller</servlet-class> </servlet> <servlet> <servlet-name>reviewcontroller</servlet-name> <servlet-class>com.taxi.service.controller.ordercontroller</servlet-class> </servlet> <servlet> <servlet-name>admincontroller</servlet-name> <servlet-class>com.taxi.service.controller.admincontroller</servlet-class> </servlet> <servlet-mapping> <servlet-name>initcontroller</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>logincontroller</servlet-name> <url-pattern>/login</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>usercontroller</servlet-name> <url-pattern>/savepersondata</url-pattern> <url-pattern>/changepassword</url-pattern> <url-pattern>/mademoderator</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>ordercontroller</servlet-name> <url-pattern>/ordercreation</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>registrationcontroller</servlet-name> <url-pattern>/registration</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>reviewcontroller</servlet-name> <url-pattern>/review</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>privateareacontroller</servlet-name> <url-pattern>/privatearea</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>admincontroller</servlet-name> <url-pattern>/adminpanel</url-pattern> </servlet-mapping> <!-- <error-page> <location>/web-inf/pages/error.jsp</location> </error-page> --> <session-config> <session-timeout>45</session-timeout> </session-config> <resource-ref> <description>db connection</description> <res-ref-name>jdbc/order_board</res-ref-name> <res-type>javax.sql.datasource</res-type> <res-auth>container</res-auth> </resource-ref> <welcome-file-list> <welcome-file>/index.jsp</welcome-file> </welcome-file-list> <login-config> <auth-method>basic</auth-method> </login-config> </web-app>
for jsp project:
create cssloader.jsp page inside folder webapp
below:
webapp -cssloader.jsp
cssloader.jsp
<link rel="stylesheet" href="resources/stylesheet/common.css"/> <link rel="stylesheet" href="resources/stylesheet/index.css"/> <script type="text/javascript" src="resources/js/validators/loginvalidator.js"></script>
then load cssloader page want import css/js file in page using <jsp:include page="../../cssloader.jsp"></jsp:include>
. for example: in case directory:
web-inf -pages -page.jsp
page.jsp
<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>web-inf inside page</title> <jsp:include page="../../cssloader.jsp"></jsp:include> </head> <body> <h1>web-inf inside page</h1> </body> </html>
note:
../../ depends upon folder level structure.
Comments
Post a Comment