简体   繁体   English

如何通过码头通配符以编程方式设置处理程序的上下文路径?

[英]How to set handlers context path programmatically with wild cards in jetty?

Usually in jetty you specify the context path in xml 通常在码头,您在xml中指定上下文路径

<bean id="myHandler" class="org.eclipse.jetty.server.handler.MyHandler">
    <property name="handler" ref="myHandler" />
    <property name="contextPath" value="/myHandler" />
</bean>

Is there a way to set a handler with wild path contextpath programmatically without xml? 有没有一种方法可以以编程方式设置带有野生路径contextpath的处理程序,而无需xml?

contextPath is the parent path for all content under that context. contextPath是该上下文下所有内容的父路径。

Jetty will only submit your request to that Handler if the contextPath matches. 如果contextPath匹配,Jetty只会将您的请求提交给该处理程序。 This is essentially a read-only value that can only be set before startup of that Handler's LifeCycle. 这实际上是一个只读值,只能在启动该处理程序的LifeCycle之前设置。

So if you used say /api then that's essentially the same as /api/* and /api/ 因此,如果您使用说/api那么它实际上与/api/*/api/

You can then use the standard HttpServletRequest details to get access to what URI was actually submitted to you. 然后,您可以使用标准的HttpServletRequest详细信息来访问实际提交给您的URI。

You might want to just use ServletContextHandler and normal Servlets if you have a need to slice/dice the URI in more complex ways. 如果您需要以更复杂的方式对URI进行切片/切块,则可能只想使用ServletContextHandler和普通的Servlet。

You can even take advantage of the PathMappings found in the ServletContextHandler to map your Servlet's in creative ways (prefix, exact, suffix, glob, regex, uri-template, etc). 您甚至可以利用ServletContextHandler中的PathMappings以创造性的方式(前缀,精确,后缀,glob,regex,uri-template等)映射Servlet。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM