RESTeasy 并返回带有模型的 JSP 页面
有没有一种简单的、不使用 spring 的方法让 RESTeasy 返回带有模型的 jsp 或 html 页面?我想做一些类似于 spring ModelAndView 的事情,我有一个请求说 /contacts/loomer 并让它在 jsp 模板中返回一个模拟对象。我看到的所有示例都是针对 JSON/XML 的。我知道在泽西岛你可以使用可视的,但我只需要使用 RESTeasy 的东西。
谢谢!
我想要这样的东西(但没有弹簧模型和视图):
@POST
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public ModelAndView saveContactForm(@Form Contact contact)
throws URISyntaxException
{
service.save(contact);
return viewAll();
}
Is there an easy, not using spring, way to have RESTeasy return a jsp or html page with a model? I want to do something similar to the spring ModelAndView where I have a request to say /contacts/loomer and have it return a mocked up object in a jsp template. All of the examples I see are for JSON/XML. I know in Jersey you can use the viewable, but I need to use only RESTeasy stuff.
Thanks!
I want something like this (but without the spring modelandview):
@POST
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public ModelAndView saveContactForm(@Form Contact contact)
throws URISyntaxException
{
service.save(contact);
return viewAll();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我已经为有兴趣的人弄清楚了。一旦我找到一个例子,这实际上是相当微不足道的。
Okay, I figured it out for anyone who is interested. It was actually fairly trivial once I found an example.
使用
org.jboss.resteasy.resteasy-html
版本3.0.6.Final
,您可以直接访问HttpServletRequest
并在定向之前注入您自己的属性输出到 RESTEasyView
。这会模拟
Htmleasy
插件的某些行为,而无需重新连接web.xml
。Using
org.jboss.resteasy.resteasy-html
version3.0.6.Final
you can directly access theHttpServletRequest
and inject your own attributes before directing output to a RESTEasyView
.This emulates some behavior of the
Htmleasy
plugin without having to rewire yourweb.xml
.我已经投票赞成上述答案,但它似乎可以与 RestEasy 一起使用,最高可达 2.3.2.Final,最新的是 2.3.5.Final(今天)。与 Glassfish 3.1.2.2 捆绑在一起的 Jersey 似乎也可以正常工作。
当我尝试时,这不适用于 2.3.2.Final 之上的 RestEasy。我想分享这个观察结果,因为我花了一段时间才弄清楚是什么导致了'java.lang.ClassCastException:$Proxy262无法转换为org.apache.catalina.core.ApplicationHttpRequest'
但是我是没有试图深入研究如何解决它,我遇到了一些想法 https://stackoverflow.com/a/5149950/1398360
干杯
I have voted up the above answer but it seems to work OK with RestEasy up to 2.3.2.Final, latest is 2.3.5.Final (for today). It seems to work OK with Jersey bundled with Glassfish 3.1.2.2 too.
This doesn't work with the RestEasy above 2.3.2.Final when I tried. I thought to share this observation as it took me a while to figure out what caused 'java.lang.ClassCastException: $Proxy262 cannot be cast to org.apache.catalina.core.ApplicationHttpRequest'
However I am not trying to dive deep how to solve it, I came across some thoughts https://stackoverflow.com/a/5149950/1398360
Cheers