如果您需要在JSP中引用CSS樣式,可以采用以下幾種方法:
1. 在JSP中直接插入CSS樣式
<html> <head> <title>Inserting CSS Style in JSP</title> <style> body { background-color: yellow; } h1 { color: blue; } </style> </head> <body> <% out.print("JSP Page with CSS Style") %> <h1>JSP Page Title</h1> <p>This is a paragraph with CSS style.</p> </body> </html>
2. 在JSP中引用外部CSS文件
<html> <head> <title>Linking to an External CSS Style Sheet</title> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head> <body> <% out.print("JSP Page with External CSS Style Sheet") %> <h1>JSP Page Title</h1> <p>This is a paragraph with CSS style.</p> </body> </html>
3. 在JSP中使用JavaScript動(dòng)態(tài)加載CSS樣式
<html> <head> <title>Loading CSS with JavaScript</title> </head> <body> <% out.print("JSP Page with JavaScript Dynamic CSS Loading") %> <h1>JSP Page Title</h1> <button onclick="loadCSS('mystyle.css')">Load CSS</button> <p>This is a paragraph with CSS style.</p> <script> function loadCSS(filename) { var file = document.createElement("link"); file.setAttribute("rel", "stylesheet"); file.setAttribute("type", "text/css"); file.setAttribute("href", filename); document.head.appendChild(file); } </script> </body> </html>
以上是在JSP中引用CSS樣式的幾種方法,您可以根據(jù)自己的需求選擇適合的方式。