In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "one-stop solution to cross-domain problems in Java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "one-stop solution to cross-domain problems in Java".
(1) js side processing: usually in the way of ajax, the following is the processing code
$.ajax ({type: "GET", url: 'common/goBD.do', xhrFields: {withCredentials: true}, crossDomain: true, success: function (data) {window.open ("http://www.baidu.com");}}))
Here we mainly pay attention to the code: xhrFields: {withCredentials: true}, indispensable; url is the address of the access server. After a successful return, you can jump to the Baidu page (open the tab page newly, of course, you can also open it on the original page).
(2) Server processing: by setting the response header information, the following is the processing code
@ RequestMapping (value= "/ goBD") public void goBD (HttpServletResponse response,HttpServletRequest request) throws IOException {String msg = "; String result =" {\ "msg\": "+ msg+"} "; PrintWriter out = response.getWriter (); response.setHeader (" Access-Control-Allow-Credentials "," true "); response.setHeader (" Access-Control-Allow-Origin ", request.getHeader (" Origin ")) Response.setHeader ("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader ("Access-Control-Max-Age", "0"); response.setCharacterEncoding ("utf-8"); out = response.getWriter (); out.write (result); out.flush (); out.close ();}
Here, we simply deal with the response header information, and do not add anything else. If there are other judgments, such as login, you can enter the user name and password on the js side for judgment processing, and make different processing in the front end by returning the value.
Thank you for your reading. the above is the content of "one-stop solution to the cross-domain problem of Java". After the study of this article, I believe you have a deeper understanding of the one-stop solution to the cross-domain problem of Java, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.