So che questa domanda è stata posta molte volte, ma non sono in grado di capire quale sia il problema. Ho la cartella delle immagini sotto la cartella src/main/webapp (questo è un progetto web maven). Ho index.jsp nella cartella src/main/webapp/WEBINF/views.Non visualizzare le immagini in Spring MVC
sto cercando di accedere alle immagini ed altre risorse, come CSS e JS come questo:
<img src="/images/left_arrow.png" alt="" />
Ma le immagini non sono sempre visualizzati.
Ecco il file web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Qui è la WEB-INF file/MVC-dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<context:component-scan base-package="com.ravi.WebApp" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
Ecco il controller pacchetto com.ravi. WebApp;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping("/")
public String printWelcome(Model model) {
return "index";
}
}
sto ottenendo questo errore dopo aver aggiunto la dichiarazione di risorse in Configurazione Primavera "alcun mapping trovato per la richiesta HTTP con URI [/ WebApp /] in DispatcherServlet con il nome 'MVC-dispatcher' " – Ravi
Ha funzionato. Il cambiamento che ho apportato è che ho fatto riferimento alle immagini nel jsp usando c: url tag "alt =" "/>. Grazie per l'aiuto – Ravi