0

I want to block a request if contains in header "addHeader". How can I do this?. I already search on Google and find doFilter method but I don't understand how I using this. There is no explanatory examples for me. In jsp file I have already write this code block;

String example  = request.getHeader("Content-Type") + " This is from req. header";
System.out.println(example);
if(example.contains("addHeader")){

    System.out.println("Contains AddHeader!!");
    Block Req.

}

Thanks for helping :)

Dusan Bajic
  • 10,249
  • 3
  • 33
  • 43
kadir
  • 23
  • 4
  • Well, you could indeed just add a [servlet filter](https://www.oracle.com/technetwork/java/filters-137243.html) in front of the struts2 filter - or use an interceptor at the top of the interceptor chain. Then just send some 4xx status code back. – Thomas Aug 19 '19 at 08:24
  • I'll deal, thanks! – kadir Aug 19 '19 at 08:35
  • I can't do this. Please more explanatory with code for interceptor chain. – kadir Aug 19 '19 at 09:20
  • Well, how to use custom interceptors can be taken from the [interceptor documention](https://struts.apache.org/core-developers/interceptors.html) (I'd suggest method 3, i.e. extending the default interceptor stack). For examples on how to implement such an interceptor you could have a look at those that are already packaged with struts 2. One thing you could do is to define a custom result for the 4xx status and then instead of calling the next invocation in the chain (i.e. instead of `return actionInvocation.invoke()`) you just return the name of that result. – Thomas Aug 19 '19 at 10:13
  • https://stackoverflow.com/a/16940296/573032 – Roman C Aug 20 '19 at 19:07

0 Answers0