You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Szűcs Attila <sz...@codespring.ro> on 2012/07/23 20:10:07 UTC

Servlet redirect

I have a screen (lets call it page X) where I do an ajax call that populates a table, constructed with jqGrid. So here I call localhost/servlet/ajax/Data.json which is a servlet. Now, if the page expires and the user still wants to access the table (search data for instance) I would like to redirect the request to the Login page.

The ajax call calls the Data.json servlet that is not in the same servlet context as my Login page (which is localhost/servlet/myapp), therefore I cannot use servlet forward (I am using JBoss 4.2 and I can only forward in the same servletcontext).

I have tried to redirect with sendRedirect, which is able to call the Login page that is actually executed but not displayed. And this is where I got lost. My Login page is executed and I still see page X. I have tried to write the returned HTML (from Login page) into the response of page X. The HTML page is actually returned, but not displayed.

How can I redirect from the servlet so that the redirected page is displayed?

Thanks,
    Atti
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
For additional commands, e-mail: user-help@turbine.apache.org


Re: Servlet redirect

Posted by Thomas Vandahl <tv...@apache.org>.
On 31.07.12 08:37, Szűcs Attila wrote:
> RunData's setRedirectURI will not work, nor will the servlet redirect (or forward). I have tested both. They do not work because I have an ajax call and ajax response always goes back to the response initiator, which in my case is the jqGrid with which I construct my tables. So I will have to do a javascript redirect.

The "Location" header is normally honored even by Ajax calls. Simply
call data.getResponse().setHeader("Location", arbitraryLocalRedirectURL);

Bye, Thomas.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
For additional commands, e-mail: user-help@turbine.apache.org


RE: Servlet redirect

Posted by Szűcs Attila <sz...@codespring.ro>.
RunData's setRedirectURI will not work, nor will the servlet redirect (or forward). I have tested both. They do not work because I have an ajax call and ajax response always goes back to the response initiator, which in my case is the jqGrid with which I construct my tables. So I will have to do a javascript redirect.

Thanks,
    Atti


-----Original Message-----
From: Sheldon Ross [mailto:ross_sheldon@hotmail.com] 
Sent: Dienstag, 31. Juli 2012 01:58
To: user@turbine.apache.org
Subject: RE: Servlet redirect


Something like this work for ya?
$data.setRedirectURI($redirectAddress)$data.setStatusCode(302)
At the top of a template with whatever if statements you want qualifying it?
Ross
> Date: Sun, 29 Jul 2012 21:32:43 +0200
> From: tv@apache.org
> To: user@turbine.apache.org
> Subject: Re: Servlet redirect
> 
> On 23.07.12 20:10, Szűcs Attila wrote:
> > How can I redirect from the servlet so that the redirected page is displayed?
> 
> I'm not quite sure I understand what you want to achieve, but there is 
> always the possibility to return a "Location" header which can 
> redirect to any URL.
> 
> Would that help?
> 
> Bye, Thomas.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
> For additional commands, e-mail: user-help@turbine.apache.org
> 
 		 	   		  

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
For additional commands, e-mail: user-help@turbine.apache.org


RE: Servlet redirect

Posted by Sheldon Ross <ro...@hotmail.com>.
Something like this work for ya?
$data.setRedirectURI($redirectAddress)$data.setStatusCode(302)
At the top of a template with whatever if statements you want qualifying it?
Ross
> Date: Sun, 29 Jul 2012 21:32:43 +0200
> From: tv@apache.org
> To: user@turbine.apache.org
> Subject: Re: Servlet redirect
> 
> On 23.07.12 20:10, Szűcs Attila wrote:
> > How can I redirect from the servlet so that the redirected page is displayed?
> 
> I'm not quite sure I understand what you want to achieve, but there is
> always the possibility to return a "Location" header which can redirect
> to any URL.
> 
> Would that help?
> 
> Bye, Thomas.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
> For additional commands, e-mail: user-help@turbine.apache.org
> 
 		 	   		  

Re: Servlet redirect

Posted by Thomas Vandahl <tv...@apache.org>.
On 23.07.12 20:10, Szűcs Attila wrote:
> How can I redirect from the servlet so that the redirected page is displayed?

I'm not quite sure I understand what you want to achieve, but there is
always the possibility to return a "Location" header which can redirect
to any URL.

Would that help?

Bye, Thomas.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
For additional commands, e-mail: user-help@turbine.apache.org


Re: Servlet redirect

Posted by tony <to...@prepare-enrich.com>.
Does your original page initially re-direct to the servlet, or just 
attempt to access it as part of the original request?

If I am understanding this correctly, I have seen a similar type of 
problem...such as a request that requires extensive processing, where 
the browser session also does not limit it to a single request (ie the 
user hammers on the submit button) then the work might be completed by 
the initial request, but it will not be able to perform a re-direct as 
the browser session is only interacting with its most recent request... 
the most recent request can re-direct, but not any of the previous 
requests (from the same form).

To solve this I basically had to write some synchronized code (within 
turbine)... allowing some initial request to perform the work, while at 
the same time allowing subsequent requests (to the same action and code) 
to recognize that the work was already complete and attempt to take the 
appropriate action... such as re-directing to an appropriate form.

(Yes I know how to solve this within the browser using Javascript, but 
in this instance it was not an
option)

The interesting thing about this is that all of the requests ARE able to 
display console output, but only the last request can re-direct...

You should be able to re-direct from any context to any other context... 
you will probably lose the session, but you should be able to re-direct...

Try re-directing within the same context... just to see if the re-direct 
itself works.

You can also implement a security model (of your own making) that 
automatically re-establishes the original session (obviously make it 
secure in some fashion).  Then when you re-direct from the servlet you 
can just assume that the original session is expired... re-direct to an 
intermediate form (in all cases) and allow that form to re-direct to the 
login page, or to another page that displays the information... etc.

I have also taken this approach when accessing external resources where 
I have no control over the timeout of the external resources, or the 
user's behaviour, etc).

best of luck

On 07/23/2012 01:10 PM, Szűcs Attila wrote:
> I have a screen (lets call it page X) where I do an ajax call that populates a table, constructed with jqGrid. So here I call localhost/servlet/ajax/Data.json which is a servlet. Now, if the page expires and the user still wants to access the table (search data for instance) I would like to redirect the request to the Login page.
>
> The ajax call calls the Data.json servlet that is not in the same servlet context as my Login page (which is localhost/servlet/myapp), therefore I cannot use servlet forward (I am using JBoss 4.2 and I can only forward in the same servletcontext).
>
> I have tried to redirect with sendRedirect, which is able to call the Login page that is actually executed but not displayed. And this is where I got lost. My Login page is executed and I still see page X. I have tried to write the returned HTML (from Login page) into the response of page X. The HTML page is actually returned, but not displayed.
>
> How can I redirect from the servlet so that the redirected page is displayed?
>
> Thanks,
>      Atti
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
> For additional commands, e-mail: user-help@turbine.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
For additional commands, e-mail: user-help@turbine.apache.org