Home » Java » java – AWS lambda/api gateway does not redirect-Exceptionshub

java – AWS lambda/api gateway does not redirect-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a very simple spring route that im attempting to run on aws lambda. The route simply returns the text/string “redirect:/upload” instead of redirecting. I have the html file in the /resources/templates folder.

@RequestMapping(path = "/test", method = RequestMethod.POST)
    public String UploadPage2() {
        return "redirect:/upload";
    }
How to&Answers:

I think the problem is from the return type of method: String.

You can do:

public RedirectView UploadPage2() {
    return new RedirectView("/upload");
}

Second question

To return an view on path /test with GET request, you need another method with same path but different method

@RequestMapping(path = "/test", method = RequestMethod.GET) 
public ModelAndView testGet(){
    return new ModelAndView("uploadview");
}