国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

java實現響應重定向發送post請求操作示例

瀏覽:58日期:2022-09-03 08:50:42

本文實例講述了java實現響應重定向發送post請求操作。分享給大家供大家參考,具體如下:

關于重定向我們用的比較多的還是redirect:重定向,默認發送的get請求。

return 'redirect:/index';

但有時候請求地址必須為post請求,比如security登錄就只能接收post請求,下面來看一下如何后臺如何發送post請求響應重定向。

首先可以定義一個map,用于存放參數鍵值對

Map<String, String> parameter = new HashMap<String, String>();

添加參數方法

public void setParameter(String key, String value) { this.parameter.put(key, value);}

發送請求代碼:

//url參數為請求地址public void sendByPost(String url) throws IOException { this.response.setContentType('text/html'); response.setCharacterEncoding('utf-8'); response.setContentType('text/html;charset=utf-8'); PrintWriter out = this.response.getWriter(); out.println('<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>'); out.println('<HTML>'); out.println(' <HEAD>'); out.println(' <meta http-equiv=Content-Type content='text/html; charset=utf-8'>'); out.println(' <TITLE>loading</TITLE>'); out.println(' <meta http-equiv='Content-Type' content='text/html charset=GBK'>n'); out.println(' </HEAD>'); out.println(' <BODY>'); out.println('<form name='submitForm' action='' + url + '' method='post'>'); Iterator<String> it = this.parameter.keySet().iterator(); while (it.hasNext()) { String key = it.next(); out.println('<input type='hidden' name='' + key + '' value='' + this.parameter.get(key) + ''/>'); } out.println('</from>'); out.println('<script>window.document.submitForm.submit();</script> '); out.println(' </BODY>'); out.println('</HTML>'); out.flush(); out.close();}

RedirectWithPost請求類全部代碼

import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.io.PrintWriter;import java.util.HashMap;import java.util.Iterator;import java.util.Map; /** * 用POST方式 重定向 * * @author royFly */public class RedirectWithPost { Map<String, String> parameter = new HashMap<String, String>(); HttpServletResponse response; public RedirectWithPost(HttpServletResponse response) { this.response = response; } public void setParameter(String key, String value) { this.parameter.put(key, value); } public void sendByPost(String url) throws IOException { this.response.setContentType('text/html'); response.setCharacterEncoding('utf-8'); response.setContentType('text/html;charset=utf-8'); PrintWriter out = this.response.getWriter(); out.println('<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>'); out.println('<HTML>'); out.println(' <HEAD>'); out.println(' <meta http-equiv=Content-Type content='text/html; charset=utf-8'>'); out.println(' <TITLE>loading</TITLE>'); out.println(' <meta http-equiv='Content-Type' content='text/html charset=GBK'>n'); out.println(' </HEAD>'); out.println(' <BODY>'); out.println('<form name='submitForm' action='' + url + '' method='post'>'); Iterator<String> it = this.parameter.keySet().iterator(); while (it.hasNext()) { String key = it.next(); out.println('<input type='hidden' name='' + key + '' value='' + this.parameter.get(key) + ''/>'); } out.println('</from>'); out.println('<script>window.document.submitForm.submit();</script> '); out.println(' </BODY>'); out.println('</HTML>'); out.flush(); out.close(); }}

實例化RedirectWithPost請求類

RedirectWithPost redirectWithPost = new RedirectWithPost(response);//redirectUrl請求地址String redirectUrl = '/login';

添加請求參數

redirectWithPost.setParameter('username', nickname);redirectWithPost.setParameter('password', openid);

調用方法,發送請求

redirectWithPost.sendByPost(redirectUrl);

更多關于java相關內容感興趣的讀者可查看本站專題:《Java Socket編程技巧總結》、《Java文件與目錄操作技巧匯總》、《Java數據結構與算法教程》、《Java操作DOM節點技巧總結》和《Java緩存操作技巧匯總》

希望本文所述對大家java程序設計有所幫助。

標簽: Java
相關文章:
主站蜘蛛池模板: 久久久国产一区二区三区丝袜 | 在线欧美日韩精品一区二区 | 国产精品综合久成人 | 男女视频在线观看 | 欧美大尺度aaa级毛片 | 日本b站一卡二不卡 | 亚洲精品国产经典一区二区 | 欧美三级在线观看不卡视频 | 亚洲天堂日韩在线 | 国产成人精品免费视频软件 | www成人国产在线观看网站 | 中文字幕亚洲一区二区va在线 | 国产精品88 | 成人综合婷婷国产精品久久免费 | 中国成人在线视频 | 高清韩国a级特黄毛片 | 中国老太卖淫播放毛片 | 欧美久在线观看在线观看 | 色多多最新地址福利地址 | 国产日韩精品视频 | 美女视频一区二区三区在线 | 亚洲a网 | 亚洲国产爱久久全部精品 | vr18成人资源 | 亚洲炮网| 欧美区一区二区三 | 国产午夜精品不卡视频 | 亚洲精品久久99久久一区 | 欧美一级毛片黄 | 久久亚洲国产中v天仙www | 久久久日本久久久久123 | 日韩经典中文字幕 | 一个人免费观看日本www视频 | 日本综合欧美一区二区三区 | 国产免费人视频在线观看免费 | 一级片欧美| 久久99国产精品 | 日本红怡院亚洲红怡院最新 | 欧美一区二区aa大片 | 免费国产a国产片高清不卡 免费国产不卡午夜福在线 免费国产不卡午夜福在线观看 | xxx本日|