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.
Open your JSP file in your favorite editor.
Locate the header section of the document (between theand tags near the top of the file).
Start a style block on a new line by adding
Hit the Enter key to add a new line below the style tag.
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.
Finish the style block by adding
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.