1. 程式人生 > >Spring MVC 後臺進行post跳轉

Spring MVC 後臺進行post跳轉

平時大多數用得還是get跳轉,今天遇到一個POST跳轉的需求,一下子就蒙圈了。

網上查得用RedirectView跳轉,試了半天,總是get跳轉,不知道是方法不對是壓根就不行。

最後還得用最笨的方法解決,唉。

直接輸出頁面:

	/**
	 * 充值跳轉頁面
	 * @param model
	 * @param request
	 * @param amt
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "/charge", method = RequestMethod.POST)
	public void  loginMethod(ModelMap model, HttpServletRequest request, String amt, HttpServletResponse response,RedirectAttributes redirectAttributes) throws Exception {
		
		Object a = request.getParameter("amt");

		String payUrl="/pay/test";// POST提交地址
		String filedName_1="amt";//如有多個,以此類推。
		String filedValue_1="123";
		
		response.setContentType( "text/html;charset=utf-8"); 
		PrintWriter out = response.getWriter();
		out.println("<form name='paySubmit' method='post'  action='"+payUrl+"' >"); 
		out.println("<input type='hidden' name='"+filedName_1+"' value='" + filedValue_1+ "'>"); //如有多個,則寫多個hidden即可
		out.println("</form>"); 
		out.println("<script>"); 
		out.println("  document.paySubmit.submit()"); 
		out.println("</script>"); 
	}