简体   繁体   中英

http get from jsp and resolve status code

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 the int value that you get you can write your if else statements and use PrintWriter 's println method to send response/text to the ajax call on your jsp and use it wherever you want in that jsp page.

您可以使用jquery并使用其ajax方法进行ajax调用,并使用其成功/错误回调方法获取textStatus

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM