1

我正在尝试重写 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

4

1 回答 1

1

原来我想要RedirectRegexRule而不是RewriteRegexRule.

于 2010-05-16T21:55:45.487 回答