SPRINGMVC02 access to static resources

Source: Internet
Author: User

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%string path = Request.getcontextpath () ; String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >the index.jsp file under the JSP folder

If you do not configure static resource access, there is no effect on the page! Because the URL of the core control we configured is/

So these static resource path pages will be intercepted! Two ways to solve it, the latter is recommended

<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" XM Lns: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 "> <display-name></display-name> <!--set up static file access--&G  T <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.jpg</    url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name&gt ;d efault</servlet-name> <url-pattern>*.css</url-pattern> </servlet-mapping> <!--configuration Spri NGMVC's core controller-<servlet> <servlet-name>springmvc</servlet-name> &LT;SERVLET-CLASS&GT;ORG.SPR Ingframework.web.servlet.DispatcherSeRvlet</servlet-class> <!--Configure the location and name of the spring configuration file---<init-param> <param-name>contextcon Figlocation</param-name> <param-value>classpath:/springmvc-servlet.xml</param-value> </ init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <u Rl-pattern>/</url-pattern> </servlet-mapping> </web-app>
1. Modify the Web. xml File
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Mvc= "Http://www.springframework.org/schema/mvc" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/sp Ring-beans-3.0.xsd Http://www.springframework.org/schema/mvc Http://www.springframework.org/schema/mvc/sprin G-mvc-3.0.xsd "> <!--Processor Mapper--<bean class=" Org.springframework.web.servlet.handler.SimpleUrlHandlerMa Pping "> <property name=" UrlMap "> <map> <entry key="/hello1 "value=" MyCo Ntroller "/> <entry key="/hello2 "value=" Mycontroller "/> <entry key="/hello3 "V                Alue= "Mycontroller"/> </map> </property> <!--<property name= "Mappings" >                 <props><prop key= "/hello1" >myController</prop> <prop key= "/hello2" >myController</prop> <prop key= "/hello3" >myController</prop> </props> &LT;/PROPERTY&G T -</bean> <!--Configure access to static resources * * represents all files under the sub-file--<mvc:resources location= "/statics/" mapping= "/sta tics/** "/> <!--processor--<bean id=" Mycontroller "class=" Cn.bdqn.controller.MyController "/> <!- -Configure View Resolver--<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > & Lt;property name= "prefix" value= "/web-inf/jsp/"/> <property name= "suffix" value= ". jsp"/> </bean&gt ;</beans>

SpringMVC02 access to static resources

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.