我面临一个奇怪的问题。
我正在使用的技术。
问题是,当我在Chrome或Opera浏览器上打开我正在开发的应用程序的页面时,css和JavaScript文件没有被应用,浏览器没有加载它们,好像它们被禁止了一样。如果我在其他浏览器(Firefox、Microsoft Edge......)上打开,页面加载正常,并应用了css和JavaScript。
在 浏览器 或 戏曲 浏览器(没有css)。
浏览器(无css):在 火狐 或 微软边缘 浏览器(带css)。
在Chrome浏览器中检查。
这些是一些文件的相关部分。
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>USUARIO</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>allowed</web-resource-name>
<url-pattern>/templates/*</url-pattern>
<url-pattern>/resources/*</url-pattern>
</web-resource-collection>
</security-constraint>
<security-role>
<role-name>USUARIO</role-name>
</security-role>
<security-role>
<role-name>NAO_AUTORIZADO</role-name>
</security-role>
<welcome-file-list>
<welcome-file>inicio.xhtml</welcome-file>
</welcome-file-list>
</web-app>
jboss-app.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-app>
<security-domain>jaspitest</security-domain>
</jboss-app>
AutenticadorUsuario.java。
@CustomFormAuthenticationMechanismDefinition(
loginToContinue = @LoginToContinue(
loginPage = "/login.xhtml",
errorPage = ""
)
)
@FacesConfig
@ApplicationScoped
public class AutenticadorUsuario implements IdentityStore
浏览器中的页面源码。
<!DOCTYPE html>
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml"><head id="j_idt2">
<title>Autenticação</title>
<meta charset="UTF-8" />
<link href="resources/css/autenticacao.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="resources/script/jquery.js"></script>
<script type="text/javascript" src="resources/script/autenticacao.js"></script>
<link href="resources/css/login.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="resources/script/login.js"></script></head><body>
<header>
</header>
<main>
<form id="form" name="form" method="post" action="/autenticacao/login.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="form" value="form" />
<div id="titulo">
Login
</div>
<div id="conteudo">
<div id="campos"><label for="form:nomeUsuario">Nome do usuário:</label><input id="form:nomeUsuario" type="text" name="form:nomeUsuario" /><label for="form:senha">Senha:</label><input id="form:senha" type="password" name="form:senha" value="" /><input type="submit" name="form:j_idt18" value="Entrar" />
</div>
</div><input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="-1019286018880157796:-2226995668037289798" autocomplete="off" />
</form>
</main>
<footer>
<p> </p>
</footer></body>
</html>
项目结构
我已经做了干净的构建,干净的部署,清除浏览器缓存,禁用杀毒软件和防火墙。问题依然存在。
如果我在我的应用程序中禁用安全功能(在web.xml中),问题就会消失(我已经检查过了)。因此,这似乎与安全有关,
但我需要在这个应用程序中启用安全功能。
如果我在浏览器上查看源代码并点击css或JavaScript文件,我得到的是
404 - 未找到
自从我发布这个问题后,我升级到Wildfly 20,想看看是否是Wildfly 19中的一个bug被纠正了,但不是。
这个应用和我用以前的JBoss或Wildfly版本开发的其他应用没有什么不同。新的是,我使用了Custom FORM认证而不是FORM认证。我还使用了新的Java EE安全软件。
这到底是怎么回事?
更新1。
嘿,你看这是什么?浏览器 和 戏曲 在做什么。正确的资源网址是这样的。
http:/localhost:8080autenticacaoresourcescssautenticacao.css。
但当安全启用时。浏览器 和 戏曲 把网址改成这样。
http:/localhost:8080resourcescssautenticacao.css。
当然资源不在这最后一个网址里。
有什么想法,为什么他们要这样做?
更新2。
我找到问题所在了 请看下面的答案。
问题解决了。
我把浏览器中的应用程序URL改成了这样。
http:/localhost:8080autenticacao。
至此。
http:/localhost:8080autenticacao。
并且成功了,资源找到了。