public class BaseAction extends ActionSupport {
public String jsonString;
public void outJsonString(String str) {
getResponse().setContentType("text/javascript;charset=UTF-8");
outString(str);
}
/*
* public void outJson(Object obj) {
* outJsonString(JSONObject.fromObject(obj).toString()); }
*
* public void outJsonArray(Object array) {
* outJsonArray(JSONArray.fromObject(array).toString()); }
*/
public void outString(String str) {
try {
PrintWriter out = getResponse().getWriter();
out.write(str);
} catch (IOException e) {
e.printStackTrace();
}
}
public void outXMLString(String xmlStr) {
getResponse().setContentType("application/xml;charset=UTF-8");
outString(xmlStr);
}
public HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
public HttpServletResponse getResponse() {
return ServletActionContext.getResponse();
}
public HttpSession getSession() {
return getRequest().getSession();
}
public ServletContext getServletContext() {
return ServletActionContext.getServletContext();
}
public String getRealyPath(String path) {
return getServletContext().getRealPath(path);
}
who can tell me~!
我在项目中也遇到了这样的问题,刚刚解决,想查一下Baseaction的用法,顺便为你解决一下问题。
BaseAction类似于supportAction,在内部实现了excute方法,在我们的框架struts2中action需要重写excute()方法的,但是我们可以通过在action.xml 配置文件中来定义result标签来标记success从而来实现跳转的jsp界面,这样在action中就不用去重写execute方法了。
BaseAction 基于ActionSupport 再次封装你需要的东西。
方便其他子类的调用。