Java 在spring中放置和使用css和js文件

Java 在spring中放置和使用css和js文件,java,html,css,spring,spring-mvc,Java,Html,Css,Spring,Spring Mvc,我是SpringMVC的新手,我已经根据教程中的教程开发了所有基本的东西,但它没有解释如何链接css文件或js文件。在stackoverflow中,我已经讨论了关于此的其他问题,但我无法解决我的问题。首先,我将从下面给出的错误开始 GET http://localhost:8082/Springtest/resources/css/bootstrap.css <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebAp

我是SpringMVC的新手,我已经根据教程中的教程开发了所有基本的东西,但它没有解释如何链接css文件或js文件。在stackoverflow中,我已经讨论了关于此的其他问题,但我无法解决我的问题。首先,我将从下面给出的错误开始

GET http://localhost:8082/Springtest/resources/css/bootstrap.css  
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 
     xmlns="http://java.sun.com/xml/ns/j2ee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
<display-name>Spring MVC Application</display-name> 
<servlet> 
    <servlet-name>Springtest</servlet-name> 
    <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
 <servlet-mapping> 
    <servlet-name>Springtest</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
下面给出了我的web.xml

GET http://localhost:8082/Springtest/resources/css/bootstrap.css  
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 
     xmlns="http://java.sun.com/xml/ns/j2ee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
<display-name>Spring MVC Application</display-name> 
<servlet> 
    <servlet-name>Springtest</servlet-name> 
    <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
 <servlet-mapping> 
    <servlet-name>Springtest</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.xml

Springtest-servlet.xml

我已经使用下面的语句链接到我的css

<link href="${pageContext.request.contextPath}/resources/css/bootstrap.css" rel="stylesheet"  type="text/css" />
下面是所用文件结构的图像


我已经标记了包含css文件的位置,我没有使用maven或pom.xml。请告诉我我在这里犯了什么错误。我也不知道maven和pom.xml在SpringMVC项目中的用法,所以一篇关于这方面的教程也会很有帮助

我在SpringMVC中使用的是AMLEAF而不是Jsp,在使用这个CSS文件之前,我在每个页面中都添加了这一行

<link rel="stylesheet" th:href="@{/frontend/css/myStyle.css}" />
与我自己的自定义JavaScript文件类似

<script th:src="@{/custom/js/myFile.js}" type="text/javascript"></script>

你能试试这个吗?我的意思是,您的Jsp页面中有这些链接吗?

我认为在资源标签中应该是

<mvc:resources mapping="/resources/**" location="/resources/" /> 
或者你应该申报

 <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
   http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

你需要去这个网址我仍然有相同的错误,它必须是其他东西。