Re: Browser Back button intercept, no javascript

2022-01-26 Thread Lukasz Lenart
It won't be possible to detect that the given request reached your
application because a user hit the Back button. There is no indication
in HTTP protocol that could tell you so.

Regards
Łukasz

wt., 25 sty 2022 o 22:58 albert kao  napisał(a):
>
> If the user presses the Back button of a browser, my application likes to
> intercept that and display a text message at the current web page.
> How to do that without using javascript?
>
> The following codes show an approach with AbstractInterceptor.
> Please review whether it will work.
> If yes, how to get the flag or value that the Back button of a browser was
> pressed?
> If not, please suggest alternatives.
> Thanks.
>
>
> import java.util.Map;
>
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpSession;
>
> import org.apache.struts2.StrutsStatics;
>
> import com.opensymphony.xwork2.ActionContext;
> import com.opensymphony.xwork2.ActionInvocation;
> import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
>
>
> public class MyInterceptor extends AbstractInterceptor {
> private Map session;
>
> @Override
> public class MyInterceptor extends AbstractInterceptor {
> private Map session;
>
> @Override
> public String intercept(ActionInvocation invocation) throws Exception {
>final ActionContext context = invocation.getInvocationContext();
>session = context.getSession();
>HttpServletRequest request = (HttpServletRequest);
>   context.get(StrutsStatics.HTTP_REQUEST);
>HttpSession httpSession = request.getSession(true);
>
>synchronized (httpSession) {
>//...
>}
>   }
> }
>
> Struts version is 2.5.26.
>
> 
> Virus-free.
> www.avg.com
> 
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Browser Back button intercept, no javascript

2022-01-25 Thread albert kao
If the user presses the Back button of a browser, my application likes to
intercept that and display a text message at the current web page.
How to do that without using javascript?

The following codes show an approach with AbstractInterceptor.
Please review whether it will work.
If yes, how to get the flag or value that the Back button of a browser was
pressed?
If not, please suggest alternatives.
Thanks.


import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.StrutsStatics;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;


public class MyInterceptor extends AbstractInterceptor {
private Map session;

@Override
public class MyInterceptor extends AbstractInterceptor {
private Map session;

@Override
public String intercept(ActionInvocation invocation) throws Exception {
   final ActionContext context = invocation.getInvocationContext();
   session = context.getSession();
   HttpServletRequest request = (HttpServletRequest);
  context.get(StrutsStatics.HTTP_REQUEST);
   HttpSession httpSession = request.getSession(true);

   synchronized (httpSession) {
   //...
   }
  }
}

Struts version is 2.5.26.


Virus-free.
www.avg.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>