strut2获取request response

package com.jy.base;

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

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport implements ServletRequestAware, ServletResponseAware {

/**
*
*/
private static final long serialVersionUID = -4860989053901044073L;


public static Logger logger = Logger.getLogger(BaseAction.class);


/**
* 当前Request
*/
protected HttpServletRequest request;

/**
* 当前Response
*/
protected HttpServletResponse response;

/*
* (non-Javadoc)
* @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
*/
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}

/*
* (non-Javadoc)
* @see org.apache.struts2.interceptor.ServletResponseAware#setServletResponse(javax.servlet.http.HttpServletResponse)
*/
public void setServletResponse(HttpServletResponse response) {
this.response = response;
}

public void htmlWrite(String val){
response.setContentType("text/html;charset=utf-8");
response.setHeader("Cache-Control", "no-cache");
try{
response.getWriter().write(val);
}catch(Exception e){
e.printStackTrace();
}
}

}

你可能感兴趣的:(apache,html,log4j,servlet,cache)