gpt4 book ai didi

java - 空上下文字符串警告

转载 作者:行者123 更新时间:2023-11-29 05:35:10 28 4
gpt4 key购买 nike

我尝试配置 jetty 上下文(以编程方式)以使用服务于根上下文的 servlet。

我为上下文路径设置了“/”,为 servlet 映射设置了“/*”。这完全按照我想要的方式工作,但 Jetty 提示(警告)以“/”结尾的上下文路径。当我将上下文路径设置为“”(空字符串)时,它会导致出现关于空字符串的警告。

documentation section of Jetty关于这个问题的状态:

Be aware
Java Servlet Specification 2.5 discourages an empty context path string, and Java Servlet Specification 3.0 effectively forbids it.

Jetty源码部分为:

public void setContextPath(String contextPath)
{
if (contextPath == null)
throw new IllegalArgumentException("null contextPath");

if (contextPath.endsWith("/*"))
{
LOG.warn(this+" contextPath ends with /*");
contextPath=contextPath.substring(0,contextPath.length()-2);
}
else if (contextPath.endsWith("/"))
{
LOG.warn(this+" contextPath ends with /");
contextPath=contextPath.substring(0,contextPath.length()-1);
}

if (contextPath.length()==0)
{
LOG.warn("Empty contextPath");
contextPath="/";
}

_contextPath = contextPath;

if (getServer() != null && (getServer().isStarting() || getServer().isStarted()))
{
Handler[] contextCollections = getServer().getChildHandlersByClass(ContextHandlerCollection.class);
for (int h = 0; contextCollections != null && h < contextCollections.length; h++)
((ContextHandlerCollection)contextCollections[h]).mapContexts();
}
}

所以问题是,我应该设置什么上下文路径才能映射到上下文的根目录。目前一切正常,但根据规范或 Jetty 警告设置了禁止的上下文路径,我想我需要一些不同的东西。

最佳答案

文档是这么说的

The context path is the prefix of a URL path that is used to select the context(s) to which an incoming request is passed. Typically a URL in a Java servlet server is of the format http://hostname.com/contextPath/servletPath/pathInfo, where each of the path elements can be zero or more / separated elements. If there is no context path, the context is referred to as the root context. The root context must be configured as "/" but is reported as the empty string by the servlet API getContextPath() method.

所以,我想你可以使用 "/"

http://www.eclipse.org/jetty/documentation/current/configuring-contexts.html

关于java - 空上下文字符串警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19768509/

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