I need to send http request to certain URL via jsp (by clicking on a link / button). Depending on the http response status code I need to generate corresponding output in the jsp (200 – action OK, 404 – unknown action etc, the content of the URL is irrelevant). Is there any way to achieve this behaviour?
I am using Spring.
First send your request to a servlet using AJAX and call the url that you want from the servlet.From that url response you can use
int status = response.getStatus();on the HttpServletResponse object in your servlet and based on theintvalue that you get you can write your if else statements and usePrintWriter‘sprintlnmethod to send response/text to the ajax call on your jsp and use it wherever you want in that jsp page.