1

In post method I did generate an object and try to send him into another Controller:

@PostMapping("/main")
    public ModelAndView makesQuery(
            @RequestParam String query
    ){
//   create new explorer if
        Explorer explorer = explorerService.createByQuery(query);

//   determine status of explorer
        StatusEnum q = StatusEnum.getEnum(explorer.getStatus().getStatusName());

        String http = q == StatusEnum.FINISHED ?
                "redirect:/show" : "redirect:/parsing";

        ModelAndView modelAndView = new ModelAndView(http);
        modelAndView.addObject("explorer", explorer);

        return modelAndView;
    }

in next method I try to get object Explorer:

@GetMapping("/parsing")
public ModelAndView makesQuery(
        @ModelAttribute Explorer explorer
) {
    ModelAndView modelAndView = new ModelAndView("search");
    modelAndView.addObject("explorer", explorer);
    return modelAndView;
}

But have next error:

Error resolving template "parsing", template might not exist or might not be accessible by any of the configured Template Resolvers


When i change annotation for Explorer from @ModelAttribute to @RequestParam:

@GetMapping("/parsing")
public ModelAndView makesQuery(
        @RequestParam Explorer explorer
) {......

I did have error in browser:

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Aug 15 14:15:52 EEST 2018 There was an unexpected error (type=Bad Request, status=400). Required Explorer parameter 'explorer' is not present

PS search.html file not have any logic in body - only string "test".

3
  • 1
    search for RedirectAttributes Commented Aug 15, 2018 at 11:30
  • see here e.g. stackoverflow.com/a/19587418/3959856 Commented Aug 15, 2018 at 11:49
  • 1
    Jack Flamp, thanks! That did help me. Commented Aug 15, 2018 at 11:54

1 Answer 1

1

You can save the explore object in session.

HttpSession session = request.getSession(true); session.setAttribute( "explorer", explorer)

And to get

@GetMapping("/parsing") public ModelAndView makesQuery(HttpServletRequest request..) HttpSession session = request.getSession(); Explore explore = session.getAttribute("exolorer")

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

2 Comments

where I can take method 'request' in string HttpSession session = request.getSession(true); session.setAttribute( "explorer", explorer) ?
public ModelAndView makesQuery( @RequestParam String query, HttpServletRequest request )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.