[Java web–3a]–spring MVC Development Considerations

Source: Internet
Author: User

1. Building a project with Maven

Problem with 2.SpringMVC absolute path

The first thing to be clear, in HTML, the resource file also has its own URL, that is, the href is the absolute path support. The following code:

<link href= "<%=request.getcontextpath ()%>/assets/css/bootstrap.min.css" rel= "stylesheet" type= "Text/css" >

When opened with a browser

<link href= "/exceptionmanagesystem/assets/css/bootstrap.min.css" rel= "stylesheet" type= "Text/css" >

In addition, you can also write this (here is to write the definition of the path variable, it is not recommended to write this)

<link rel= "apple-touch-icon-precomposed" sizes= "144x144" href= "<%=request.getscheme () +"://"+ Request.getservername () + ":" +request.getserverport () + Request.getcontextpath ()%>/assets/ico/ Kingadmin-favicon144x144.png ">

When opened with a browser, it is with IP address + port

<link rel= "apple-touch-icon-precomposed" sizes= "144x144" href= "http://localhost:8080/ExceptionManageSystem/ Assets/ico/kingadmin-favicon144x144.png ">

3. Issues where resource files cannot be displayed

In Springmvc, there are some configurations to be aware of, such as:

Web. XML code Fragment 1:

<filter-mapping>    <filter-name>encodingFilter</filter-name>    <url-pattern>/</ Url-pattern></filter-mapping>

Web. XML code Fragment 2:

<servlet-mapping>    <servlet-name>springMVC</servlet-name>    <url-pattern>/</ Url-pattern> </servlet-mapping>

Spring configuration file Code Snippet 3: (Configure static resources, directly mapped to the corresponding folder, not handled by Dispatcherservlet, 3.04 new features, need to reset spring-mvc-3.0.xsd)

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

If one of the above 3 types is improperly configured, it will cause the resource file to not be displayed

4. Problems with absolute resource path unreachable in CSS style (inexplicable problem, record only)

In the project that I am writing now has CSS to use the resource file under Other folder (can display normally on Firefox, but it is not shown on chrom), for example:

[Java web–3a]–spring MVC Development Considerations

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.