package com.edianxun.adp.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

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

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport{

	/**
	 * @author lhr
	 * @date  2014-4-29
	 */
	private static final long serialVersionUID = 1893151512645757572L;

	/**
	 * get session
	 */
	public Map<String, Object> getSession(){
		return ActionContext.getContext().getSession();
	}
	
	/**
	 * get response by ServletActionContext
	 * @return response
	 */
	public HttpServletResponse getResponse(){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/html; charset=UTF-8");
		return response;
	}
	
	/**
	 * get request by ServletActionContext
	 * @return request
	 */
	public HttpServletRequest getRequest(){
		return ServletActionContext.getRequest();
	}
	
	/**
	 * open PrintWrite
	 * @return pw
	 */
	public PrintWriter getWriter(){
		HttpServletResponse response = this.getResponse();
		PrintWriter pw = null;
		try {
			pw = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return pw;
	}
	
	/**
	 * close PrintWrite
	 * @param pw
	 */
	public void close(PrintWriter pw){
		if (pw != null) {
			pw.close();
		}
	}
	
	/**
	 * write json string
	 * @param json
	 */
	public void outJson(String json){
		PrintWriter pw = this.getWriter();
		pw.write(json);
		this.close(pw);
	}
	
}
最近下载更多
17787885952  LV3 2022年5月5日
wanglinddad  LV51 2022年4月14日
王燕燕  LV3 2021年12月23日
afei115  LV4 2021年11月20日
cailizhu833  LV2 2021年8月17日
Vera.Wu  LV2 2021年5月29日
and123456  LV11 2021年4月20日
admin_z  LV17 2021年4月18日
小屁孩  LV7 2021年4月11日
weijianjiao  LV1 2021年3月14日
最近浏览更多
lt12138  LV2 10月25日
dsadasdwf  LV12 10月23日
1049066887  LV12 10月21日
张朕朕  LV3 9月8日
288984827  LV1 8月25日
uni-code_0123  LV1 8月21日
飞呀飞呀飞不放  LV7 8月8日
shaoqi 7月26日
暂无贡献等级
admin686  LV2 7月4日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友