Home > Net >  Accessing url with model and view on Spring Boot project
Accessing url with model and view on Spring Boot project

Time:09-17

Hi a Java newbie here.

I am trying to send a URL via modelAndView to an html page that is using thymeleaf.

My controller looks something like this.

@RequestMapping("/api/test")
public ModelAndView test(){
    ModelAndView modelAndView = new ModelAndView();
    String google = "www.google.com";
    modelAndView.addObject("google", google);
    modelAndView.setViewName("api/googleTest");
    return modelAndView;
}

And my the button where I am using this attribute looks something like this

<button class="w-100 btn btn-secondary btn-lg" type="button"
                th:onclick="|location.href='@{{link}(link=${google})}'|">

And when I push the button, my application seems to redirect to http://localhost:8080/api/www.google.com instead of www.google.com

It would be sincerely appreciated if there would be a way to fix this problem. Thank you in advance!!

CodePudding user response:

You missed to setup the Path variable into your controller.

Go through with below URL

https://www.baeldung.com/spring-pathvariable

if still not clear ping me back.

CodePudding user response:

What happens when you add "http://"?

Like String google = "http://www.google.com";

  • Related