JSP Web site to introduce external CSS or JS failure problem solving _javascript skills

Source: Internet
Author: User
Tags java web

Recently done projects, complete the task assigned by the project manager, started the Java Web, but encountered many problems in the development process, but I have the most headaches or import external CSS has been ineffective, plagued for a long time to find out why.

Path issues

CSS or JS import failure is the most likely reason is the path error, here I give my Site directory structure, you can refer to.

To import CSS code:

<link rel= "stylesheet" type= "Text/css" href= "Css/login.css" >

Remember that the JSP head needs to set a relative path:

  <%
    String Path = Request.getcontextpath ();
    String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
  %>

Set the filter

I just set up a login filter to cause CSS and JS invalidation. The solution is simple, set the request path that the filter intercepts (filter associated URL style) to the appropriate file, for example, I filter the JSP file, so my XML part is configured as follows:

  <filter-mapping>
    <filter-name>login</filter-name>
    <url-pattern>/.jsp</ Url-pattern>
  </filter-mapping>

Thank you for reading, I hope to help you, thank you for your support for this site!

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.