我在将 javascript 文件加载到我的 JSP 页面时遇到问题。相反,css文件正在正常加载。
在我的 *.jsp 文件中,我在“header”部分加载脚本:
<script type="text/javascript" src="js/resources.js" charset="utf-8"></script>
在这个 index.jsp 文件的顶部,我指定了字符集:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
而且在头部:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
WildFly(第 11 版)返回的错误是:
Exception handling request to /trust/js/resources.js: java.lang.IllegalArgumentException: Null charset name
其中“/trust/js/resources.js”是我自己尝试加载的 js 文件。
每个 *.js 文件都会出现此错误
完整的错误堆栈:15:24:32,670 错误 [io.undertow.request](默认任务 55)UT005023:对 /trust/js/resources.js 的异常处理请求:
java.lang.IllegalArgumentException: Null charset name
at java.base/java.nio.charset.Charset.lookup(Charset.java:467)
at java.base/java.nio.charset.Charset.forName(Charset.java:538)
at io.undertow.servlet//io.undertow.servlet.core.BlockingWriterSenderImpl.<init>(BlockingWriterSenderImpl.java:66)
at io.undertow.servlet//io.undertow.servlet.core.ServletBlockingHttpExchange.getSender(ServletBlockingHttpExchange.java:76)
at io.undertow.core//io.undertow.server.HttpServerExchange.getResponseSender(HttpServerExchange.java:1316)
at io.undertow.servlet//io.undertow.servlet.handlers.DefaultServlet.serveFileBlocking(DefaultServlet.java:345)
at io.undertow.servlet//io.undertow.servlet.handlers.DefaultServlet.doGet(DefaultServlet.java:185)
at javax.servlet.api//javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.api//javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at deployment.trust-3.1.46.war//eu.dovira.servlet.filter.ServletAccessLogger.doFilter(ServletAccessLogger.java:74)
at io.undertow.servlet//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at deployment.trust-3.1.46.war//eu.dovira.servlet.filter.NocacheFilter.doFilter(NocacheFilter.java:54)
at io.undertow.servlet//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at deployment.trust-3.1.46.war//eu.dovira.servlet.filter.TreeHtmlFilter.doFilter(TreeHtmlFilter.java:50)
at io.undertow.servlet//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at deployment.trust-3.1.46.war//eu.dovira.servlet.filter.RequestEncodingFixer.doFilter(RequestEncodingFixer.java:48)
at io.undertow.servlet//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at deployment.trust-3.1.46.war//eu.dovira.servlet.filter.RouterFilter.doFilter(RouterFilter.java:54)
at io.undertow.servlet//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at deployment.trust-3.1.46.war//eu.dovira.servlet.filter.SetHttpHeadersFilter.doFilter(SetHttpHeadersFilter.java:118)
at io.undertow.servlet//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.core//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.core//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.core//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.core//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.core//io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
at io.undertow.core//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.base/java.lang.Thread.run(Thread.java:844)
Firefox 浏览器通过每个 js 文件(在其开发人员工具包中)返回错误,如下图所示: 在此处输入图像描述
提前感谢所有答案!