繁体   English   中英

在Spring IDE中哪里保存关于html / jsp页面的css,javascript和图像文件?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM