I am working with the following controller from the Spring In Practice book:
The project is using an InternalResourceViewResolver. As you can see, the postComment() method is mapped to a URL of the form: "http://localhost:8080/sip/articles/{article-name}/commnets", where my web application context path is "/sip". When I hit this method (which saves a comment to an article), as you see above, the method does a redirect to view named by the
string {pageNumber + "#comment-" + comment.getId()}, where pageNumber and comment.getId() are integers. This should form a string of the form: "1#commnet-5" for pageNumber = 1 and comment.getId() = 5. The return statement will then be: return "redirect:1#comment-5";. When I hit this method in the application with these values, it redirects to the URL "http://localhost:8080/sip/{article-name}/1?null". My understanding of redirect: was that it takes the view that follows ':' as the redirect URL, so it seems like it should have redirected to "http://localhost:8080/sip/1#comment-5". I don't see where the redirected URL is getting the {article-name} from and why it is dropping the "#comment-5". Also, as part of
testing I changed the statement to: [return "redirect:";] and the URL I got was "http://localhost:8080/sip/#postComment". Could someone enlighten me as to what is going on. I am obviously not fully understanding how redirect: works in Spring. Thank you in advance.