第一步,先写一个jsp页面,定义jsp将form表单提交给SiglePaymentServlet
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SR</title>
</head>
<body>
<H2>单笔代扣发单</H2>
<form action="TestServlet" method="post">
<input type="text" name="test1" /><br/>
<input type="text" name="test2" /><br/>
<input type="submit" value="提交" />
</form>
</body>
</html>
2第二步,创建TestServlet
package com.test;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
/** * Servlet implementation class TestServlet */
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private String url="";
private String merchId="";
private String key="";
/** * @see HttpServlet#HttpServlet() */
public TestServlet() {
super();
// TODO Auto-generated constructor stub
}
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String test1=request.getParameter("test1") ;
System.out.println(test1);
Map<String, String> paraMap = new HashMap<String, String>();
url=request.getParameter("url");
merchId=request.getParameter("merchId");
key=request.getParameter("key");
paraMap.put("test1", request.getParameter("test1"));
paraMap.put("test2", request.getParameter("test2"));
JSONObject jsob = JSONObject.fromObject(paraMap);
String content = jsob.toString();
String res = HttpClientUtil.post(url, content,merchId,key);
PrintWriter out = response.getWriter();
out.print(res);
}
}
3关于调用的httpclient,和签名方法,可以请教相关开发进行获取。