0

I have Spring Boot 2.0 thyemeleaf/spring reactor based web app. I have this code in controller:

Mono.just("redirect:/error/404"); 

Which is run if bad user enters invalid query string params. The redirect works fine but the URL changes to:

/error/404 

instead of keeping the original user entered URL like this

/home?gp=badvalue 

How to do redirect while keeping the original URL in the browser address bar?

Note that this web app will run in embedded servlet container (in this case Netty).

0

1 Answer 1

1

With redirect redirect:/error/404, server will respond with a 302 and the new URL in the Location header; the browser/client will then make another request to the new URL.

Try to use forward:

return new ModelAndView("forward:/redirectedUrl", model); 

forward happens entirely on a server side; the Servlet container forwards the same request to the target URL; the URL won’t change in the browser

Refererence in here

Sign up to request clarification or add additional context in comments.

2 Comments

thank u for info but forward does not work in reactive spring boot app. No method signature defined for Mono.just("forward:/error/404", model); and Mono.just("forward:/error/404"); throws error.
I don’t have too much experience in reactive spring boot app. But, I found the issue in here. The issue is still open. Looking for comments to get more solutions or you can try another method that using javascript at client side...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.