gpt4 book ai didi

java - Spring Security无法加载资源: the server responded with a status of 404

转载 作者:行者123 更新时间:2023-12-01 10:19:33 25 4
gpt4 key购买 nike

当我导航到经过身份验证的 url 时,所有静态内容(甚至 url 内部的 href)都已附加到路由的 url 中,因为该页面中的所有资源以及 href 元素内的所有 url 都会收到 404

对于例如

    <security:http auto-config="true" use-expressions="false"> 
<security:intercept-url pattern="/reports/**" access="ROLE_USER"/>
<security:intercept-url pattern="/**" access="ROLE_ANONYMOUS"/>

<security:form-login login-page="/login.do" login-processing-url="/login.do" username-parameter="custom_username"
password-parameter="custom_password"
authentication-success-handler-ref="authSuccessHandler"
default-target-url="/"
always-use-default-target="true"
authentication-failure-url="/login.do?error=true"/>
<security:logout logout-url="/logout.do" logout-success-url="/login.do?logout=true"/>
<security:csrf disabled="true"/>
</security:http >

<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="user1" password="password" authorities="ROLE_USER"/>
<security:user name="admin" password="password" authorities="ROLE_USER,ROLE_FOO"/>
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<security:http pattern="**/styles/**" security="none" />
<security:http pattern="**/js/**" security="none" />

当我导航到myapp/reports/时,我的静态内容已更改为

enter image description here

通常在 html 中它看起来像

<link href="styles/jqueryUI.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="styles/Home.css">
<link rel="stylesheet" href="styles/metisMenu.min.css">
<link rel="stylesheet" href="styles/sideBar.css">

即使我启用了 mvc:resources,我还是错过了一些东西

<mvc:annotation-driven/>
<mvc:resources mapping="/WebContent/styles/**" location="css/" />
<mvc:resources mapping="/WebContent/js/**" location="js/" />
<mvc:resources mapping="/WebContent/images/**" location="images/" />
<mvc:resources mapping="/WebContent/fonts/**" location="fonts/" />

最佳答案

您的资源映射和链接标记的 href 属性存在问题。由于您还没有发布您的目录结构让我解释一下如何制作示例 map :这是我的目录结构: enter image description here

如果我想将customestyle.min.css 添加到我的html 页面,我需要以下设置:

<mvc:resources mapping="/contents/css/**" location="/contents/css/" />

<link type="text/css" rel="stylesheet" href='<c:url value="/contents/css/customestyle.min.css"/> '/>

关于java - Spring Security无法加载资源: the server responded with a status of 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35696840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com