[英]Where to keep the css, javascript and image files with respect to html/jsp pages in Spring IDE?
我正在使用Eclipse Europa IDE和Tomcat服務器在Spring MVC Framework中開發Web應用程序
我的目錄結構是(部分):
- WebContent
- WEB-INF
- pages
- CSS
- images
- login.html
- dispatcher-servlet.xml
- web.xml
在我的login.html中,我有一個指向css文件的鏈接
<link rel="stylesheet" type="text/css" href="CSS/loginregister.css" media="screen">
由於我的login.html和CSS文件夾位於同一文件夾“pages”中,我認為這樣可行。
但不 。 css文件未加載(login.html顯示順利)
我也嘗試過:
<HREF = “/ CSS / loginregister.css”>
<HREF = “頁面/ CSS / loginregister.css”>
我通過我的控制器類訪問login.html。
我的URL是這樣的: http://localhost:8080/AccountCreation/login.htm
誰能告訴我問題出在哪里?
將“pages”文件夾移動到WebContent而不是WEB-INF。 JSP頁面在WEB-INF下受到保護,但不受css,js,html等靜態文件的保護。
應用程序上下文的根是WebContent,它將被引用為
http://server.com/contextroot/
最佳做法是創建一個文件夾WebContent / css並將文件loginregister.css放在那里。 您的鏈接將是
<link rel="stylesheet" type="text/css" href="css/loginregister.css" media="screen">
要進行測試,只需在瀏覽器中輸入以下URL即可確保按預期從上下文根提供css文件
http://server.com/contextroot/css/loginregister.css
[編輯]
對於您的初始測試,也將您的login.html放在WebContent(例如WebContent/login.html
)中,但是您已經提到過您正在使用Spring,因此您最終可能會使用等效的JSP替換login.html。
http://server.com/contextroot/login.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.