java直接跳转页面
public static String genForwardHtml(String url, Map<String, String> parameters, String charset) { StringBuffer returnHtml = new StringBuffer(""); if (!"".equals(url)) { returnHtml.append("<html>"); String head = "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + charset + "\" pageEncoding=\"" + charset + "\" />"; returnHtml.append(head); returnHtml.append("<title>loading</title>"); returnHtml.append("<style type=\"text/css\">"); returnHtml.append( "body{margin:200px auto;font-family: \"宋体\", Arial;font-size: 12px;color: #369;text-align: center;}"); returnHtml.append("#1{height:auto; width:78px; margin:0 auto;}"); returnHtml.append("#2{height:auto; width:153px; margin:0 auto;}"); returnHtml.append("vertical-align: bottom;}"); returnHtml.append("</style>"); returnHtml.append("</head>"); returnHtml.append("<body>"); returnHtml.append("<div id=\"3\">交易处理中...</div>"); returnHtml.append("<form name=\"forwardForm\" action=\"").append(url).append("\" method=\"POST\">"); System.out.println("WebUtils genForwardHtml::url=" + url); Iterator keyIterator = parameters.keySet().iterator(); while (keyIterator.hasNext()) { Object key = keyIterator.next(); returnHtml.append(" <input type=\"hidden\" name=\"").append(key.toString()).append("\" value=\"") .append((String) parameters.get(key)).append("\"/>"); System.out.println("WebUtils genForwardHtml::" + key.toString() + "=" + parameters.get(key)); } returnHtml.append("</form>"); returnHtml.append("<SCRIPT LANGUAGE=\"Javascript\">"); returnHtml.append(" document.forwardForm.submit();"); returnHtml.append("</SCRIPT>"); returnHtml.append("</body>"); returnHtml.append("</html>"); } return returnHtml.toString(); }
调用方式
String result = WebUtils.genForwardHtml(url, paramMap, "utf-8"); OutputStream out = response.getOutputStream(); out.write(result.getBytes("utf-8")); out.flush();
看完打开支付宝扫一扫领个红包吧!