gpt4 book ai didi

java - 如何在 java 中配置 war 应用程序以允许从 GET 方法访问资源目录?

转载 作者:行者123 更新时间:2023-11-29 05:04:24 27 4
gpt4 key购买 nike

我正在尝试使用 wildfly,但我不知道如何允许访问某些资源。

我的 index.jsp 需要获取一些 js 文件。但是在加载相应网页的时候。我观察到这个错误:

GET http://localhost:8080/resources/jquery-ui/external/jquery/jquery-2.1.4.min.js [HTTP/1.1 405 Method Not Allowed 4ms]
GET http://localhost:8080/resources/jquery-ui/jquery-ui.min.js [HTTP/1.1 405 Method Not Allowed 1ms]

索引.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>GROOLS</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script async="defer" src="<%=request.getContextPath()%>/resources/jquery-ui/external/jquery/jquery-2.1.4.min.js"> </script>
<script async="defer" src="<%=request.getContextPath()%>/resources/jquery-ui/jquery-ui.min.js"> </script>

</head>
<body>

</body>
</html>

网络.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<security-constraint>
<web-resource-collection>
<web-resource-name>allowed</web-resource-name>
<url-pattern>/resources/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
</security-constraint>
</web-app>

jboss-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>/</context-root>
</jboss-web>

结构

$ tree -d src/
src/
└── main
├── java
│   └── fr
│   └── foo
│   └── bar
│   └── wildfly
│   └── service
├── resources
│   └── META-INF
└── webapp
├── resources
│   └── jquery-ui
│   ├── external
│   │   └── jquery
│   └── images
└── WEB-INF

问候

最佳答案

据我了解:http://docs.oracle.com/cd/E19798-01/821-1841/gjjcd/index.html在 web-resource-collection 中指定一个模式拒绝访问,而不指定它允许。因此:

    <web-resource-collection>
<web-resource-name>allowed</web-resource-name>
<url-pattern>/resources/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>

此配置主动拒绝对资源的 GET 请求。

关于java - 如何在 java 中配置 war 应用程序以允许从 GET 方法访问资源目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30919273/

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