एक Maven परियोजना में, सबसे पहले, आप
<mvc:resources mapping="/resources/**" location="/resources/" />
या
<resources mapping="/resources/**" location="/resources/" />
अपने सर्वलेट-config.xml फ़ाइल को जोड़ना होगा (यह मेरी परियोजना में spring-servlet.xml है)।
उसके बाद, एक फ़ोल्डर "संसाधन" बनाएं यदि यह src/main/webapp के अंतर्गत मौजूद नहीं है। अपने सीएसएस फ़ोल्डर को रखें जिसमें सीएसएस फाइलें हों, छवि फ़ोल्डर जिसमें फ़ोल्डर संसाधनों के तहत छवि फाइलें हों।
<img src="<%=request.getContextPath() %>/resources/images/image.jpg"/>
या
<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/css/style.css" />
मेरे वसंत-servlet.xml फ़ाइल:
<?xml version="1.0" encoding="windows-1252"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- Use @Component annotations for bean definitions -->
<context:component-scan base-package="form"/>
<!-- Use @Controller annotations for MVC controller definitions -->
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- Add JPA support -->
<bean id="emf" class=
"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="loadTimeWeaver">
<bean class=
"org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>
<!-- Add Transaction support -->
<bean id="myTxManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emf"/>
</bean>
<!-- Use @Transaction annotations for managing transactions -->
<tx:annotation-driven transaction-manager="myTxManager" />
<!-- View resolver -->
<bean class=
"org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
</bean>
</beans>
परियोजना
अब आप के रूप में JSP फ़ाइल से संसाधन फ़ोल्डर के अंतर्गत किसी भी फ़ाइल का उपयोग कर सकते कंकाल:
src
--main
--webapp
--resources
--css+
--images+
--target
... आदि
इसमें कोई .js या .css फ़ाइलें शामिल नहीं हैं? –
मैं जेएसपी में 'src/main/resource' में मौजूद जेएस, सीएसएस, छवियों के लिंक कैसे जोड़ सकता हूं? – OO7
ऐसा लगता है कि मेवेन पेज में उपर्युक्त संरचना नहीं है। – RuntimeException