2017-06-02 112 views
0

的success.jsp显示图像MVC

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Success page</title> 
</head> 
<body> 

    <img alt="Preview not available" src="/images/photo.jpg" /><br /><br /> 



</body> 
</html> 

弹簧-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:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.3.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"> 

    <context:component-scan base-package="co" /> 
    <mvc:annotation-driven /> 
    <mvc:resources location="/images/**" mapping="/images/" /> 
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/jsp/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
     <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
     <property name="url" value="jdbc:mysql://localhost:3306/springs" /> 
     <property name="username" value="root" /> 
     <property name="password" value="medusa" /> 
     <property name="maxActive" value="20" /> 
     <property name="maxIdle" value="5" /> 
     <property name="maxWait" value="5000"></property> 
    </bean> 
    <bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate"> 
     <property name="dataSource" ref="dataSource"></property> 
    </bean> 

    <bean id="multipartResolver" 
     class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 

     <!-- setting maximum upload size --> 
     <property name="maxUploadSize" value="10000000" /> 

    </bean> 


</beans> 

Application Structure

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>FileUploading02</groupId> 
    <artifactId>FileUploading02</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 
    <build> 
    <sourceDirectory>src</sourceDirectory> 
    <plugins> 
     <plugin> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.5.1</version> 
     <configuration> 
      <source>1.8</source> 
      <target>1.8</target> 
     </configuration> 
     </plugin> 
     <plugin> 
     <artifactId>maven-war-plugin</artifactId> 
     <version>3.0.0</version> 
     <configuration> 
      <warSourceDirectory>WebContent</warSourceDirectory> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 

    <dependencies> 
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.36</version> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp --> 
    <dependency> 
     <groupId>commons-dbcp</groupId> 
     <artifactId>commons-dbcp</artifactId> 
     <version>1.4</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-tx</artifactId> 
     <version>4.3.6.RELEASE</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --> 
    <dependency> 
     <groupId>commons-fileupload</groupId> 
     <artifactId>commons-fileupload</artifactId> 
     <version>1.3.2</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> 
    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>2.5</version> 
    </dependency> 

    </dependencies> 
</project> 

我所看到的这个特定的问题是在这里被问了很多,并提供了许多解决方案,但是当我应用该解决方案将 标记添加到我的Spring-servlet时,仍然没有运气。当我在服务器上运行我的成功页面时,它会显示图像的替代文字。而且,这些图像是静态的,只能保存在我的应用程序中。

+0

尝试添加您的war_name:Preview not available VNT

+0

不,它不工作 – PraKhar

+0

你能在这里贴上您的网址 – VNT

回答

0

改变文件

弹簧-servlet.xml中

<mvc:resources location="/images/" mapping="/images/**" /> 

的success.jsp

<img alt="Preview not available" src="/FileUploading02/images/photo.jpg" /> 

我解决它通过添加这两个变化。

感谢VNT为您的时间。