当前位置: 首页 > 知识库问答 >
问题:

spring安全加载资源失败:服务器以404的状态响应

锺英卫
2023-03-14

当我导航到authenticated url时,所有静态内容(甚至是href中的url)都与路由的url附加在一起,因为我得到的是该页面中的所有资源和href元素中的所有url的404

对于E.X

    <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/my静态内容已更改为

通常在html中看起来像

null

<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">

null

我在这里错过了一些东西,甚至我已经enebled了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/"  />

共有1个答案

唐哲
2023-03-14

如果要将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"/> '/>
 类似资料:
  • 我有一个带有ASP. NET Core Web API后端和Angulal-13前端的项目。 Web API有这样一个endpoint:https://localhost:5001/api/v1/admin/teachers 登录后,当我将生成的不记名令牌粘贴到POSTMAN时,它会给出这样的结果: 从Angular前端,我有这些代码。 角度 teacher.service: 教师组件: 我本以为

  • 我正在运行一个spring MVC应用程序,下面是我的项目结构。 在我的中,我尝试在header部分加载js。 但我在浏览器中发现了以下错误。 在我的spring文件中,我添加了 有人能指出我犯的错误吗?

  • 我在我的服务器上部署反应应用程序,它在localhost上运行良好,但当我试图在我的服务器上使用它时,我得到了 加载资源失败:服务器响应状态为404(未找到)shayankh。me/graphql 我在服务器上的根位置是 /var/www/html/ '这是我的server.js 和索引。js 我不知道我的问题出在哪里。是否有可能是因为服务器的根位置,我的应用程序找不到GraphQL?我还在我的服

  • 我在浏览器中收到错误消息“加载资源失败:服务器响应状态为404”,我正在使用Node/Express、Mongo数据库和Docker。没有Docker一切正常。 文件夹结构: 后端 服务器 服务器。js公司 src公司 索引。html server.js 指数html 包裹json{脚本} 文档文件 docker编写。yml公司 如果我在浏览器中输入“192.168.99.100:3000/gal

  • Im在使用@RequestMapping(method=RequestMethod.Post)注释向controller类添加方法时遇到了一个问题。问题是我什么时候添加这个方法并启动应用程序。应用程序无法加载资源(css、JS等)。在浏览器上,我得到:无法加载资源:服务器以405(方法不允许)的状态响应,在运行日志上,我得到以下消息:org.springframework.web.servlet.

  • 我正在学习Lynda关于Javascript和Ajax以及hungup的教程,主题是“使用同步XHR请求”。 html文件基本上是: javascript文件为: data.txt文件上有“Hello World”。 项目文件的路径为 当我打开wampserver上的localhost并执行inspect元素时,我得到了上面的错误:“未能加载资源:服务器响应状态为404(not found)” 不