jsp - static resource mapping in spring mvc -
i did mapping image files in spring context file below:
<mvc:resources mapping="/images/**" location="/web-inf/images/" /> i tested direct accessing of image in url in browser address bar: hhttp://host:port/managedepartments/images/oracle.png
it renders requested image on browser why it's preventing spring controller url serving user request. after url mapping images in spring context file, when seek below url returning 404 error.
http://host:port/managedepartments/department/ not getting section home page after doing image mapping in context file!
for jsp, below configuration in spring configuration file:
<bean id="jspviewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver" p:prefix="/web-inf/jsp/" p:suffix=".jsp" /> below project structure:
any suggestion highly appreciated!
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_2_5.xsd" version="2.5"> <display-name>spring mongodb web application</display-name> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/dispatcher-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> </web-app> dispatcher
<?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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:component-scan base-package="com.rislg" /> <mvc:resources mapping="/images/**" location="/web-inf/images/" /> <!-- mill bean creates mongo instance --> <bean id="mongo" class="org.springframework.data.mongodb.core.mongofactorybean"> <property name="host" value="localhost" /> </bean> <!-- mongotemplate connecting , quering documents in database --> <bean id="mongotemplate" class="org.springframework.data.mongodb.core.mongotemplate"> <constructor-arg name="mongo" ref="mongo" /> <constructor-arg name="databasename" value="test" /> </bean> <!-- utilize post processor translate mongoexceptions thrown in @repository annotated classes --> <bean class="org.springframework.dao.annotation.persistenceexceptiontranslationpostprocessor" /> <bean id="jspviewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver" p:prefix="/web-inf/jsp/" p:suffix=".jsp" /> </beans> in console, not looking error in browser getting http status 404 when nail hhttp://host:port/managedepartments/department/ working before getting section home page.
rgrds
as explain in this other post there no way spring-mvc allow serving resources straight under root and map root url controller.
but in utilize case, resources not straight under root, , should plenty map dispatcherservlet /* instead of / in web.xml file.
jsp spring-mvc static-resource
No comments:
Post a Comment