Java 在Spring MVC 3.0.2中显示图像
我正在使用Spring3.0.2 当我试图显示一个图像时,我得到的只是一个带有红十字的盒子。我也尝试过使用Java 在Spring MVC 3.0.2中显示图像,java,spring,hibernate,jsp,spring-mvc,Java,Spring,Hibernate,Jsp,Spring Mvc,我正在使用Spring3.0.2 当我试图显示一个图像时,我得到的只是一个带有红十字的盒子。我也尝试过使用 <mvc:resources mapping="/resources/**" location="/resources/" /> 但是我得到一个错误 匹配的通配符是严格的,但找不到元素“mvc:resources”的声明 我也尝试过添加SpringV4JAR,但它们现在与以前的jar冲突 这是我的spring-servlet.xml <?xml versi
<mvc:resources mapping="/resources/**" location="/resources/" />
但是我得到一个错误匹配的通配符是严格的,但找不到元素“mvc:resources”的声明 我也尝试过添加SpringV4JAR,但它们现在与以前的jar冲突 这是我的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>
类路径:hibernate.cfg.xml
${jdbc.dial}
真的
这是我的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>
项目
welcome.jsp
春天
org.springframework.web.servlet.DispatcherServlet
1.
春天
/
下面是jsp代码:
<img src="<c:url value="/images/ciscoimg.jpg" />"/>
“/>
以下是我的目录结构:
如果您的mvc:resources设置与您的img src标记不匹配,我将非常感谢您对如何显示我的图像的任何帮助。 首先,改变
<mvc:resources mapping="/resources/**" location="/resources/" />
并将img标记的src更改为
/resources/images/path/to/image
,但是当我使用mvc:resources标记时,会出现什么错误呢?请检查
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources" />
<mvc:resources mapping="/resources/**" location="/" />