java - Display image in Spring MVC 3.0.2 -
i'm using spring 3.0.2 when try display image, box red cross. have tried using
<mvc:resources mapping="/resources/**" location="/resources/" />
but error
"the matching wildcard strict, no declaration can found element 'mvc:resources' "
i have tried adding spring v4 jar conflicting previous jars.
here spring-servlet.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd " > <context:component-scan base-package="com.pack1" /> <mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/resources/" /> <context:annotation-config /> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/display/"/> <property name="suffix" value=".jsp" /> </bean> <bean id="propertyconfigurer" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer" p:locations="/web-inf/jdbc.properties" /> <bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close" p:driverclassname="${jdbc.driverclassname}" p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> <bean id="sessionfactory" class="org.springframework.orm.hibernate3.annotation.annotationsessionfactorybean"> <property name="datasource" ref="datasource" /> <property name="configlocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">${jdbc.dialect}</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <tx:annotation-driven /> <bean id="transactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory" /> </bean>
here web.xml:
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="webapp_id" version="2.5"> <display-name>project</display-name> <welcome-file-list> <welcome-file>welcome.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
and here jsp code:
<img src="<c:url value="/images/ciscoimg.jpg" />"/>
here directory structure:
any highly appreciated how can display image
your mvc:resources setting not match img src tag. first of all, change
<mvc:resources mapping="/resources/**" location="/resources/" />
to
<mvc:resources mapping="/resources/**" location="/web-inf/resources" />
and move static files(or folders) under /web-inf/resources directory.
and correct img tag's src starting /resources/path/to/image
.
but if images not need secured, can let static files them , change mvc:resources
<mvc:resources mapping="/resources/**" location="/" />
and change img tag's src /resources/images/path/to/image
Comments
Post a Comment