Spring MVC: Introducing CSS into the JSP

Source: Internet
Author: User

In order to introduce the CSS into the JSP, today is really stepping on a lot of pits, and finally found a solution on the StackOverflow, not much to say the code.

Add the following code to Web. XML:

< servlet-mapping >    < Servlet-name >default</servlet-name>    <Url-pattern  >*.css</url-pattern>     </  Servlet-mapping>

The Spring-servlet.xml configuration is as follows:

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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-3.0.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/cont Ext/spring-context-3.0.xsd Http://www.springframework.org/schema/mvc HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MV C/spring-mvc.xsd ">    <Mvc:annotation-driven/>    <Mvc:default-servlet-handler/>        <mvc:resourcesMapping= "/resources/**" Location= "/resources/css/"Cache-period= "31556926"/>        <!--Scan Web packages, apply spring annotations -    <Context:component-scanBase-package= "Main.com.winjay.blog.web"/>            <!--Configure the View resolver to parse Modelandview and strings into specific pages -    <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"P:viewclass= "Org.springframework.web.servlet.view.JstlView"P:prefix= "/web-inf/"P:suffix= ". jsp" />            </Beans>

Still not finished here, I began to put CSS containing floder in the Web-inf directory, found that still can not introduce CSS, and then I put that floder in the Webroot directory successfully introduced!

Spring MVC: Introducing CSS into the JSP

Related Article

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.