card
card

Reputation: 33

How to stop Spring redirect url getting encoded

i am using below code in spring return new ModelAndView("https://test.com?query1=value1&query2=Value2") That is getting encoded to value = https://test.com?query1%3Dvalue1%26query2%3Value2 in the browser.

How to correct this, What changes needed to make it correct formed url. is this tomcat or browser doing this?

Problem is i am trying to get by parameter by name but not able to get it. As the name has been changed with some special character.

request.getParameter("query1")

Upvotes: 1

Views: 779

Answers (1)

Drexpp
Drexpp

Reputation: 28

You could try to add those attributes to the model and view, just as

ModelAndView res = new ModelAndView("https://test.com");
res.addAttribute("query1", value1);
res.addAttribute("query2", value2);

To retrieve them, you can use

 Object param1 = (Object) request.getAttribute("query1");

being Object your type of Object for the attribute

Update 1:

If last try didn't work, go ahead and use this alternative:

String message = "SomeText"
return new ModelAndView("redirect:" + "welcome", "message", message);

This message variable will be available in URL as a GET request

http://localhost:80/test/welcome?message=SomeText

Update 2:

I suppose you are using Controllers, so try to add to the RequestMapping annotation the following attribute

@RequestMapping(value = "...whatever you have", produces = 
   "text/plain;charset=UTF-8")

Upvotes: 1

Related Questions