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

muk*_*und 3 java eclipse spring-mvc

我正在使用Eclipse Europa IDE和Tomcat服务器 在Spring MVC Framework中开发Web应用程序

我的目录结构是(部分):

- WebContent  
    - WEB-INF  
        - pages  
            - CSS  
            - images  
            - login.html  
        - dispatcher-servlet.xml  
        - web.xml  
Run Code Online (Sandbox Code Playgroud)

在我的login.html中,我有一个指向css文件的链接

<link rel="stylesheet" type="text/css" href="CSS/loginregister.css" media="screen">
Run Code Online (Sandbox Code Playgroud)

由于我的login.html和CSS文件夹位于同一文件夹"pages"中,我认为这样可行.
.css文件未加载(login.html显示顺利)

我也尝试过:

<href ="/ CSS/loginregister.css">
<href ="pages/CSS/loginregister.css">

我通过我的控制器类访问login.html .
我的网址是这样的:http://localhost:8080/AccountCreation/login.htm

谁能告诉我问题出在哪里?

Bra*_*rad 5

将"pages"文件夹移动到WebContent而不是WEB-INF.JSP页面在WEB-INF下受到保护,但不受css,js,html等静态文件的保护.

应用程序上下文的根是WebContent,它将被引用为

http://server.com/contextroot/
Run Code Online (Sandbox Code Playgroud)

最佳做法是创建一个文件夹WebContent/css并将文件loginregister.css放在那里.您的链接将是

<link rel="stylesheet" type="text/css" href="css/loginregister.css" media="screen"> 
Run Code Online (Sandbox Code Playgroud)

要进行测试,只需在浏览器中输入以下URL,即可确保按预期从上下文根提供css文件

http://server.com/contextroot/css/loginregister.css
Run Code Online (Sandbox Code Playgroud)

[编辑]

对于您的初始测试,也将您的login.html放在WebContent(例如WebContent/login.html)中,但是您已经提到过您正在使用Spring,因此您最终可能会使用等效的JSP替换login.html.

http://server.com/contextroot/login.html
Run Code Online (Sandbox Code Playgroud)