[英]Where to keep the css, javascript and image files with respect to html/jsp pages in Spring IDE?
I am developing an web application in Spring MVC Framework with Eclipse Europa IDE and
Tomcat server
我正在使用Eclipse Europa IDE和
Tomcat服务器在Spring MVC Framework中开发Web应用程序
My directory structure is(partial): 我的目录结构是(部分):
- WebContent
- WEB-INF
- pages
- CSS
- images
- login.html
- dispatcher-servlet.xml
- web.xml
In my login.html I have a link to a css file as 在我的login.html中,我有一个指向css文件的链接
<link rel="stylesheet" type="text/css" href="CSS/loginregister.css" media="screen">
Since my login.html and CSS folder are in the same folder "pages" I thought this would work. 由于我的login.html和CSS文件夹位于同一文件夹“pages”中,我认为这样可行。
But NO .
但不 。 The css file didn't load (login.html appears smoothly)
css文件未加载(login.html显示顺利)
I also tried: 我也尝试过:
<href="/CSS/loginregister.css">
<HREF = “/ CSS / loginregister.css”>
<href="pages/CSS/loginregister.css"><HREF = “页面/ CSS / loginregister.css”>
I am accessing the login.html via my controller class .
我通过我的控制器类访问login.html。
my URL comes like this: http://localhost:8080/AccountCreation/login.htm
我的URL是这样的:
http://localhost:8080/AccountCreation/login.htm
Can any one tell me where is the problem ? 谁能告诉我问题出在哪里?
Move your "pages" folder to be under WebContent instead of WEB-INF. 将“pages”文件夹移动到WebContent而不是WEB-INF。 JSP pages shold be protected under WEB-INF but not static files like css, js, html.
JSP页面在WEB-INF下受到保护,但不受css,js,html等静态文件的保护。
The root of your application context is WebContent which would be referenced as 应用程序上下文的根是WebContent,它将被引用为
http://server.com/contextroot/
Best practise would say to create a folder WebContent/css and place your file loginregister.css in there. 最佳做法是创建一个文件夹WebContent / css并将文件loginregister.css放在那里。 Your link will then be
您的链接将是
<link rel="stylesheet" type="text/css" href="css/loginregister.css" media="screen">
To test, you can simply enter the following URL in your browser to ensure that the css file is being served from your context root as expected 要进行测试,只需在浏览器中输入以下URL即可确保按预期从上下文根提供css文件
http://server.com/contextroot/css/loginregister.css
[EDIT] [编辑]
For your initial testing, also place your login.html in WebContent (eg WebContent/login.html
) as well, however you have mentioned you're using Spring so you'll probably end up replacing login.html with an equivalent JSP. 对于您的初始测试,也将您的login.html放在WebContent(例如
WebContent/login.html
)中,但是您已经提到过您正在使用Spring,因此您最终可能会使用等效的JSP替换login.html。
http://server.com/contextroot/login.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.