码迷,mamicode.com
首页 > 编程语言 > 详细

springmvc 重定向为post请求

时间:2019-01-16 12:01:45      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:report   repo   exception   mvc   mon   com   shm   flush   end   

package com.foresee.zxpt.common.utils;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

public class HttpClientPostFs {

	private static Map<String, String> parameter = new HashMap<String, String>();
	private HttpServletResponse response;

	public HttpClientPostFs() {
	}

	public HttpClientPostFs(HttpServletResponse response) {
		this.response = response;
	}

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

	public void sendByPost(String url) throws IOException {
		this.response.setContentType("text/html");
		PrintWriter out = this.response.getWriter();
		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		out.println("<HTML>");
		out.println(" <HEAD><TITLE>sender</TITLE></HEAD>");
		out.println(" <BODY>");
		out.println("<form name=\"submitForm\" action=\"" + url + "\" method=\"post\">");
		Iterator<String> it = HttpClientPostFs.parameter.keySet().iterator();
		while (it.hasNext()) {
			String key = it.next();
			out.println("<input type=\"hidden\" name=\"" + key + "\" value=\"" + HttpClientPostFs.parameter.get(key) + "\"/>");
		}
		out.println("</from>");
		out.println("<script>window.document.submitForm.submit();</script> ");
		out.println(" </BODY>");
		out.println("</HTML>");
		out.flush();
		out.close();
	}
}
x
48
 
1
package com.foresee.zxpt.common.utils;
2
3
import java.io.IOException;
4
import java.io.PrintWriter;
5
import java.util.HashMap;
6
import java.util.Iterator;
7
import java.util.Map;
8
9
import javax.servlet.http.HttpServletResponse;
10
11
public class HttpClientPostFs {
12
13
    private static Map<String, String> parameter = new HashMap<String, String>();
14
    private HttpServletResponse response;
15
16
    public HttpClientPostFs() {
17
    }
18
19
    public HttpClientPostFs(HttpServletResponse response) {
20
        this.response = response;
21
    }
22
23
    public void setParameter(String key, String value) {
24
        HttpClientPostFs.parameter.put(key, value);
25
    }
26
27
    public void sendByPost(String url) throws IOException {
28
        this.response.setContentType("text/html");
29
        PrintWriter out = this.response.getWriter();
30
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
31
        out.println("<HTML>");
32
        out.println(" <HEAD><TITLE>sender</TITLE></HEAD>");
33
        out.println(" <BODY>");
34
        out.println("<form name=\"submitForm\" action=\"" + url + "\" method=\"post\">");
35
        Iterator<String> it = HttpClientPostFs.parameter.keySet().iterator();
36
        while (it.hasNext()) {
37
            String key = it.next();
38
            out.println("<input type=\"hidden\" name=\"" + key + "\" value=\"" + HttpClientPostFs.parameter.get(key) + "\"/>");
39
        }
40
        out.println("</from>");
41
        out.println("<script>window.document.submitForm.submit();</script> ");
42
        out.println(" </BODY>");
43
        out.println("</HTML>");
44
        out.flush();
45
        out.close();
46
    }
47
}
48

@RequestMapping(value = {"showDownloadInfo"})
	public void showDownloadInfo( HttpServletRequest request, HttpServletResponse response, String ids) {
		try {
			String[] idArr = ids.split("&amp;");
			String id=idArr[0];
			TZxptQtSqxxbTo sqxxbTo = sqxxbToService.get(id);
			String requestId = sqxxbTo.getRequestId();
			String url= "/zxpt-web"+frontPath + "/report/downloadQyzxbg4PDFNew";
			HttpClientPostFs http=new HttpClientPostFs(response);
			http.setParameter("requestId",requestId);//将参数封装到这个里面,以键值对的形式存在
			http.sendByPost(url);//重定向的地址
		} catch (IOException e) {
			logger.error(e.getMessage());
		}
	}
1
15
1
@RequestMapping(value = {"showDownloadInfo"})
2
    public void showDownloadInfo( HttpServletRequest request, HttpServletResponse response, String ids) {
3
        try {
4
            String[] idArr = ids.split("&amp;");
5
            String id=idArr[0];
6
            TZxptQtSqxxbTo sqxxbTo = sqxxbToService.get(id);
7
            String requestId = sqxxbTo.getRequestId();
8
            String url= "/zxpt-web"+frontPath + "/report/downloadQyzxbg4PDFNew";
9
            HttpClientPostFs http=new HttpClientPostFs(response);
10
            http.setParameter("requestId",requestId);//将参数封装到这个里面,以键值对的形式存在
11
            http.sendByPost(url);//重定向的地址
12
        } catch (IOException e) {
13
            logger.error(e.getMessage());
14
        }
15
    }

springmvc 重定向为post请求

标签:report   repo   exception   mvc   mon   com   shm   flush   end   

原文地址:https://www.cnblogs.com/gz9218/p/8650f010d5e777470cf4f15e4e30da48.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!