Java构造函数

public class Util_HttpPost {
	String url = "";
	HttpPost httpRequest;
	List<NameValuePair> params;
	String result;//服务器返回结果
	public Util_HttpPost(String url, Map<String, String> map) {

		// 请求数据
//		 httpRequest = new HttpPost(Variable.accessaddress+"dbutil");
		 httpRequest = new HttpPost(url);
		// 创建参数
		 params = new ArrayList<NameValuePair>();
		//遍历传进来的map参数
		Set set = map.keySet();
		Iterator it = set.iterator();
		while (it.hasNext()) {
			String key = (String) it.next();
			String value = map.get(key);

			params.add(new BasicNameValuePair(key, value));
		}
/*		不要在构造函数里调用执行方法,因为构造函数只能返回类对象实例
		通过这样来调用commodityId = new Util_HttpPost(Variable.accessaddress
		+ "sendcommodity", getParamsMap()).post();
		 post();  
*/	
	}

	public String post() {

你可能感兴趣的:(Java构造函数)