一个 ajax 的工具包。可用于strutsX.X

package com.util.comm.actions;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * [email protected]
 * @author linlin yu
 * @version 1.0
 */
public class BaseAction extends ActionSupport implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	public HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}

	public void outJsonString(String json) {
		getResponse().setContentType("text/javascript;charset=UTF-8");
		outString(json);
	}

	public void outJson(Object obj) {
		outJsonString(JSONObject.fromObject(obj).toString());
	}

	public void outJsonArray(Object array) {
		outJsonArray(JSONArray.fromObject(array).toString());
	}

	public void outString(String json) {
		try {
			PrintWriter out = getResponse().getWriter();
			out.write(json);
		} catch (IOException e) {
		}
	}

	public void outXMLString(String xmlStr) {
		getResponse().setContentType("application/xml;charset=UTF-8");
		outString(xmlStr);
	}

}

 

 

下面还有一个包

你可能感兴趣的:(java,json,Ajax,servlet,Gmail)