users@jersey.java.net

[Jersey] Re: seeOther and some data

From: Arthur Yeo <artyyeo_at_gmail.com>
Date: Fri, 15 Apr 2011 14:01:02 -0700

Incidentally, can ${it} work reliably in a piece of Javascript that's
embedded in the JSP ?


On Fri, Apr 15, 2011 at 1:51 PM, Arthur Yeo <artyyeo_at_gmail.com> wrote:

> OK, I can go without the param and slap whatever I need to pass thru in
> that Viewable Obj,
>
> I am able to access the data from the JSP using ${it} now.
>
> However, when I get to the JSP page, the URL on the browser does not change
> to the target JSP page URL but remains at the URL of the original resource;
> i.e. the URL of the rsrc that passed out the Viewable obj.
>
> Is there way to make the URL change, just like Response.seeOther ?
>
> --
> Arthur
>
>
> On Fri, Apr 15, 2011 at 9:37 AM, Arthur Yeo <artyyeo_at_gmail.com> wrote:
>
>> Thanks, Daniel, for the highlight about Template.
>>
>> How does one include the params in the URL, then, for Viewable?
>> Is there a way to do that?
>>
>>
>> On Thu, Apr 14, 2011 at 7:52 PM, Daniel Larsson <
>> daniel.j.larsson_at_gmail.com> wrote:
>>
>>> The parameter to Viewable is not an URL, but a relative path. If you give
>>> a name, such as "foo", it will look for pages named
>>> <package-as-path>/<Classname>/foo.jsp (the actual lookup is a bit more
>>> sophisticated than that, actually, but google around, or turn on more
>>> verbose logging to see what paths it searches to find your JSP file).
>>>
>>> So, if your resource class is com.example.Resource, and you return new
>>> Viewable("foo") name your JSP file /com/example/Resource/foo.jsp. This is
>>> relative your web root.
>>>
>>>
>>> 2011/4/15 Arthur Yeo <artyyeo_at_gmail.com>
>>>
>>>> OK, I found something in some older threads and looks looks like the way
>>>> to do this is to return a Viewable object.
>>>>
>>>> I changed the server code to do this now:
>>>>
>>>> return new Viewable("http://localhost:8080/MyPage.jsp", MyObject);
>>>>
>>>> And, the JSP page has this code embedded to show what's coming thru:
>>>> <h1><% out.println ("New data==" + (MyObject)
>>>> request.getAttribute("someField")); %></h1>
>>>>
>>>> Questions:
>>>>
>>>> 1. Do I need to declare @Produces ("application/html") or is it
>>>> something else since I am returning a Viewable object?
>>>> 2. What's causing this run time error?
>>>>
>>>>
>>>> Here's the run-time error:
>>>>
>>>> PWC1406: Servlet.service() for servlet ServletAdaptor threw exception
>>>> java.io.IOException: The template name,
>>>> http://localhost:8080/MyPage.jsp, could not be resolved to a fully
>>>> qualified template name at
>>>> com.sun.jersey.server.impl.template.ViewableMessageBodyWriter.writeTo(ViewableMessageBodyWriter.java:74)
>>>> at
>>>> com.sun.jersey.server.impl.template.ViewableMessageBodyWriter.writeTo(ViewableMessageBodyWriter.java:58)
>>>> at
>>>> com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:289)
>>>> at
>>>> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1029)
>>>> at
>>>> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
>>>> at
>>>> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
>>>> at
>>>> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
>>>> at
>>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
>>>> at
>>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
>>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at
>>>> org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
>>>> at
>>>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
>>>> at
>>>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
>>>> at
>>>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
>>>> at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97) at
>>>> com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
>>>> at
>>>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
>>>> at
>>>> org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
>>>> at
>>>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
>>>> at
>>>> com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
>>>> at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
>>>> at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) at
>>>> com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) at
>>>> com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
>>>> at
>>>> com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
>>>> at
>>>> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
>>>> at
>>>> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
>>>> at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
>>>> at
>>>> com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
>>>> at
>>>> com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
>>>> at com.sun.grizzly.ContextTask.run(ContextTask.java:69) at
>>>> com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
>>>> at
>>>> com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
>>>> at java.lang.Thread.run(Thread.java:662)
>>>>
>>>>
>>>> On Thu, Apr 14, 2011 at 2:55 PM, Arthur Yeo <artyyeo_at_gmail.com> wrote:
>>>>
>>>>> At the end of a servicing a Jersey request, I need to do these 2
>>>>> things:
>>>>>
>>>>> 1. redirect it to a JSP page
>>>>> 2. and include a few pieces of data wrapped in an object for that
>>>>> JSP page to use
>>>>>
>>>>> What are the best practice approaches to implementing this?
>>>>>
>>>>> Currently, I am doing this ...
>>>>>
>>>>> ---------------
>>>>> ResponseBuilder builder = Response.seeOther(URI.create("
>>>>> http://localhost:8080/My.jsp")) );
>>>>> builder.entity(MyObject);
>>>>> if (EverythingIsSunny == 1) {
>>>>> return builder.build();
>>>>> } else {
>>>>> return Response.seeOther(URI.create("
>>>>> http://localhost:8080/SomeErrorHandlingPage.html")).build();
>>>>> }
>>>>> ------------------
>>>>>
>>>>> When I ran it, I get a runtime exception that looks like the one below.
>>>>> Any recommendations?
>>>>>
>>>>> javax.ws.rs.WebApplicationException
>>>>> at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:268)
>>>>> at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1029)
>>>>> at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
>>>>> at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
>>>>> at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
>>>>> at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
>>>>> at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
>>>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
>>>>> at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
>>>>> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
>>>>> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
>>>>> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
>>>>> at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
>>>>> at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
>>>>> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
>>>>> at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
>>>>> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
>>>>> at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
>>>>> at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
>>>>> at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
>>>>> at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
>>>>> at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
>>>>> at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
>>>>> at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
>>>>> at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
>>>>> at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
>>>>> at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
>>>>> at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
>>>>> at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
>>>>> at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
>>>>> at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
>>>>> at java.lang.Thread.run(Thread.java:662)
>>>>>
>>>>>
>>>>> --
>>>>> Arthur Y.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Arthur Y.
>>>>
>>>
>>>
>>
>>
>> --
>> Arthur Y.
>>
>
>
>
> --
> Arthur Y.
>



-- 
Arthur Y.