我正在尝试重写 servlet 的 URL。URL 被正确重写,但此后上下文不匹配。知道如何让它工作吗?
RewriteHandler rewriteHandler = new RewriteHandler();
rewriteHandler.setRewriteRequestURI(true);
rewriteHandler.setRewritePathInfo(true);
rewriteHandler.setOriginalPathAttribute("requestedPath");
RewriteRegexRule rewriteRegexRule = new RewriteRegexRule();
rewriteRegexRule.setRegex("/r/([^/]*).*");
rewriteRegexRule.setReplacement("/r?z=$1");
rewriteHandler.addRule(rewriteRegexRule);
ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
Context servletContext = new Context(contextHandlerCollection, "/");
servletContext.addServlet(new ServletHolder(new RedirectServlet()), "/r");
所以基本上/r/asdf
被重写为/r?z=asdf
.
/r?z=asdf
但是, servlet 现在不处理重写的内容。
此外,/r?z=asdf
如果直接调用也可以。
我在这里粘贴了完整的代码:http: //pastebin.com/Z1isNADg