How to Reference a CSS File From JSP

One of the benefits of Java Server Pages (JSP) is that you can let your Web server do some of the work traditionally left to your visitor's Web browser. In traditional static HTML, CSS (cascading) stylesheets are referenced using the "link" tag, requiring your visitor's Web browser to fetch the stylesheet before rendering your Web page. Using JSP, you can include the CSS directly, making faster Web pages for your visitors.

Things You'll Need

  • JSP file
  • CSS stylesheet file
  • Text editor
Show More

Instructions

    • 1

      Open your JSP file in your favorite editor.

    • 2

      Locate the header section of the document (between the <head> and </head> tags near the top of the file).

    • 3

      Start a style block on a new line by adding <style type="text/css">. Hit the "Enter" key to add a new line below the style tag.

    • 4

      Add a reference to your CSS stylesheet using the JSP "include" directive by adding <%@include file="style.css" %>. Use the correct path and filename of your stylesheet in place of "style.css." Hit the "Enter" key to add a new line below the JSP tag.

    • 5

      Finish the style block by adding </style>.

    • 6

      Save the file and test it. When your JSP file is executed, it will copy the contents of your CSS stylesheet into the style block of the HTML generated by the JSP.

Tips & Warnings

  • If your JSP executes without errors, but the page is not styled according to your CSS stylesheet, make sure the directory path and file name are correct. The directory path is relative to the JSP file. On some Web servers, the file name may be case-sensitive. Make certain the path and file name in the JSP are spelled exactly as they appear on the server.

Related Searches:

References

Resources

Comments

You May Also Like

  • How to Include CSS File in ASP

    Cascading Style Sheets are handy ways to make layout styles for your webpages. CSS styles can be saved in the webpage file...

  • How to Work With CSS in Nvu

    Nvu is an open source WYSIWYG HTML editor that is used to create web pages. It is available for free from nvudev.com...

  • How to Read a JSP File

    The JSP file extension indicates that the file is a Java Server Page file. Java Server Pages are scripted HTML code pages...

  • JSP Web Tutorial

    JavaServer Pages (JSP) is a technology that allows you to create dynamic web pages by embedding Java programming language code in your...

  • How to Convert HTML to JSP

    JSP allows you to embed snippets of the Java programming language into HTML tags to create interactive content. HTML pages are static...

  • The Advantages of Custom Tags

    The Advantages of Custom Tags. Custom Java Server Page (JSP) tags are tags that a developer implements using regular Java classes. With...

  • How to Use Margins in CSS

    The Cascading Style Sheet (CSS) property called margin will add space to the outside of any element in your HTML document. Margin...

  • How to Become a UI Software Engineer

    When you buy a computer, appliance or similar electronic device, a UI software engineer has most likely mulled over how you'll interact...

  • How to Open JSP Files in Photoshop CS4

    Graphic designers are known to incorporate anything and everything into their designs. Being able to recognize and work with myriad file extensions...

  • How to Write to a Text File From JSP

    To embed the logic to write to a file into a JSP page, wrap the Java code in <% and %> and...

Related Ads

Featured