配置Restlet以在Google App Engine上返回JSP?

我开发了一个Restlet应用程序。 我想通过Restlet返回URL请求的JSP文件。 如何在不使用重定向的情况下实现此目的?

即假设我在mydomain.com上有“contact.jsp”文件,我希望人们能够访问http://mydomain.com/contact上的 contact.jsp

因此,在Restlet中,我会:

router.attach("/contact", MyResource.class); 

但是如何返回“contact.jsp”页面呢? 我知道重定向会起作用,但我不希望用户在“ http://mydomain.com/contact.jsp ”中看到“.jsp”…或者是否有其他策略可以在没有使用的情况下工作的Restlet? 也许我的web.xml文件有些修改?

编辑(2009-08-14):

我在下面发布的答案不适用于App-Engine和Restlet。 但是,如果我不包含Restlet,或者允许Restlet具有“/ *”的url模式,它确实有效

什么是理想的是有一个允许我这样做的路由器的子类:

 router.attach("/contact", "/contact.jsp"); 

谢谢!

编辑(2009-08-17):

自从我发布赏金以来,我没有得到任何答复,我感到很惊讶。 如果我的问题/问题不明确,有人会发表评论并告诉我吗?

编辑(2009-08-17):

有趣的观察。 使用下面“Rich Seller”描述的方法时,它可以在Google App-Engine上部署,而不是在本地部署。 此外,如果我在Google App-Engine上调用http://mydomain.com/contact.jsp ,它会绕过Restlet并直接进入JSP。 但是,在本地,Restlet接管了。 也就是说, http:// localhost:8080 / contact.jsp没有进入JSP并转到Restlet。 部署的应用引擎应用程序对URL的响应方式与本地对应方式不同吗?

“我想通过Restlet在URL请求上返回一个JSP文件” – 我的理解是JSP被转换为servlet。 由于Servlet是Restlet的正交,因此不确定如何通过Restlet返回JSP文件。

假设您要求使用除Restlet之外的JSP的方法,最好通过将restlet映射到root路径(例如/ rest而不是/ *)并像往常一样使用.jsp来实现。

Restlet目前不直接支持JSP。 它们很难在servlet容器之外处理。

有关这个问题的讨论你可能会觉得有用,目前看起来你需要将重定向返回到在web.xml中正常映射的JSP,或者破解它来处理JSP并返回流作为代表。

该主题中的“2009年4月23日;下午03:02”的回复描述了如何进行黑客攻击:

 if (request instanceof HttpRequest && ((HttpRequest) request).getHttpCall() instanceof ServletCall) { ServletCall httpCall = (ServletCall) ((HttpRequest) request).getHttpCall(); // fetch the HTTP dispatcher RequestDispatcher dispatcher = httpCall.getRequest().getRequestDispatcher("representation.jsp"); HttpServletRequest proxyReq = new HttpServletRequestWrapper(httpCall.getRequest()); // Overload the http response stream to grab the JSP output into a dedicated proxy buffer // The BufferedServletResponseWrapper is a custom response wrapper that 'hijacks' the // output of the JSP engine and stores it on the side instead of forwarding it to the original // HTTP response. // This is needed to avoid having the JSP engine mess with the actual HTTP stream of the // current request, which must stay under the control of the restlet engine. BufferedServletResponseWrapper proxyResp = new BufferedServletResponseWrapper(httpCall.getResponse()); // Add any objects to be encoded in the http request scope proxyReq.setAttribute("myobjects", someObjects); // Actual JSP encoding dispatcher.include(proxyReq, proxyResp); // Return the content of the proxy buffer Representation rep = new InputRepresentation(proxyResp.toInputStream(),someMediaType); 

BufferedServletResponseWrapper的源代码稍后会发布几个条目。

看起来像一个简单的web.xml配置。

  contactServlet /contact.jsp   contactServlet /contact  

这在App-Engine中没有Restlet。 但是一旦我包含Restlet,如果我将我的Reslet url-pattern设置为“/ *”,它就不起作用