BaseAction 类

网友投稿 688 2022-10-29

BaseAction 类

BaseAction 类

import java.io.IOException; import java.util.HashMap; import java.util.Map;import javax.servlet.ServletContext; import javax.servlet.import javax.servlet-.sf.json.JSONObject;import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class BaseAdminAction extends ActionSupport { private static final long serialVersionUID = 6718838822334455667L; public static final String VIEW = "view"; public static final String LIST = "list"; public static final String BizAUCTIONLIST = "businessauctionlist"; public static final String CharitableAUCTIONLIST = "charitableauctionlist"; public static final String ChoujiangLIST = "choujianglist"; public static final String ZhongjiangLIST = "zhongjianglist"; public static final String ThanksfulLIST = "thanksfullist"; public static final String STATUS = "status"; public static final String WARN = "warn"; public static final String SUCCESS = "success"; public static final String ERROR = "error"; public static final String MESSAGE = "message"; public static final String CONTENT = "content"; public static final String HTMLDIV = "htmldiv"; protected String id; protected String[] ids; //apnids peversionids osversionids areaids devmodelids protected String[] apnids; protected String[] peversionids; protected String[] osversionids; protected String[] areaids; protected String[] devmodelids; protected String[] a_devmodelids; protected String[] p_devmodelids; protected String[] s_devmodelids; protected String[] k_devmodelids; protected String[] le1_devmodelids; protected String[] other_devmodelids; public static final String ALLDEVICES="ALL_DEVICES"; protected String[] all_deviceids; protected Pager pager; protected String logInfo;// 日志记录信息 protected String redirectionUrl;// 操作提示后的跳转URL,为null则返回前一页 protected String[] test_e2eboss_ids; protected String[] test_pushteam_ids; protected String[] test_otherteam_ids; public String input() { return null; } // 获取Attribute public Object getAttribute(String name) { return ServletActionContext.getRequest().getAttribute(name); } // 设置Attribute public void setAttribute(String name, Object value) { ServletActionContext.getRequest().setAttribute(name, value); } // 获取Parameter public String getParameter(String name) { return getRequest().getParameter(name); } // 获取Parameter数组 public String[] getParameterValues(String name) { return getRequest().getParameterValues(name); } // 获取Session public Object getSession(String name) { ActionContext actionContext = ActionContext.getContext(); Map session = actionContext.getSession(); return session.get(name); } // 获取Session public Map getSession() { ActionContext actionContext = ActionContext.getContext(); Map session = actionContext.getSession(); return session; } // 设置Session public void setSession(String name, Object value) { ActionContext actionContext = ActionContext.getContext(); Map session = actionContext.getSession(); session.put(name, value); } // 获取Request public HttpServletRequest getRequest() { return ServletActionContext.getRequest(); } // 获取Response public HttpServletResponse getResponse() { return ServletActionContext.getResponse(); } // 获取Application public ServletContext getApplication() { return ServletActionContext.getServletContext(); } // AJAX输出,返回null public String ajax(String content, String type) { try { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType(type + ";charset=UTF-8"); //response.setHeader("Pragma", "No-cache"); //response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.getWriter().write(content); response.getWriter().flush(); } catch (IOException e) { e.printStackTrace(); } return null; } // AJAX输出,返回null public String ajaxAndFowardTo(String content, String type,String fowardto) { try { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType(type + ";charset=UTF-8"); //response.setHeader("Pragma", "No-cache"); //response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.getWriter().write(content); response.getWriter().flush(); } catch (IOException e) { e.printStackTrace(); } return fowardto; } // AJAX输出文本,返回null public String ajaxText(String text) { return ajax(text, "text/plain"); } // AJAX输出HTML,返回null public String ajaxHtml(String html) { return ajax(html, "text/html"); } // AJAX输出XML,返回null public String ajaxXml(String xml) { return ajax(xml, "text/xml"); } // 根据字符串输出JSON,返回null public String ajaxJson(String jsonString) { return ajax(jsonString, "text/html"); } // 根据Map输出JSON,返回null public String ajaxJson(Map jsonMap) { JSONObject jsonObject = JSONObject.fromObject(jsonMap); return ajax(jsonObject.toString(), "text/html"); } // 输出JSON警告消息,返回null public String ajaxJsonWarnMessage(String message) { Map jsonMap = new HashMap(); jsonMap.put(STATUS, WARN); jsonMap.put(MESSAGE, message); JSONObject jsonObject = JSONObject.fromObject(jsonMap); return ajax(jsonObject.toString(), "text/html"); } // 输出JSON成功消息,返回null public String ajaxJsonSuccessMessage(String message) { Map jsonMap = new HashMap(); jsonMap.put(STATUS, SUCCESS); jsonMap.put(MESSAGE, message); JSONObject jsonObject = JSONObject.fromObject(jsonMap); return ajax(jsonObject.toString(), "text/html"); } // 输出JSON成功消息,返回null public String ajaxJsonOKMsgAndForwardto(String message,String forwardto) { Map jsonMap = new HashMap(); jsonMap.put(STATUS, SUCCESS); jsonMap.put(MESSAGE, message); JSONObject jsonObject = JSONObject.fromObject(jsonMap); return ajaxAndFowardTo(jsonObject.toString(), "text/html",forwardto); } // 输出JSON错误消息,返回null public String ajaxJsonErrorMessage(String message) { Map jsonMap = new HashMap(); jsonMap.put(STATUS, ERROR); jsonMap.put(MESSAGE, message); JSONObject jsonObject = JSONObject.fromObject(jsonMap); return ajax(jsonObject.toString(), "text/html"); } // 输出JSON成功消息,返回null public String ajaxJsonSuccessHTMLMessage(String message,String html) { Map jsonMap = new HashMap(); jsonMap.put(STATUS, SUCCESS); jsonMap.put(MESSAGE, message); jsonMap.put(HTMLDIV, html); JSONObject jsonObject = JSONObject.fromObject(jsonMap); return ajax(jsonObject.toString(), "text/html"); } // 设置页面不缓存 public void setResponseNoCache() { getResponse().setHeader("progma", "no-cache"); getResponse().setHeader("Cache-Control", "no-cache"); getResponse().setHeader("Cache-Control", "no-store"); getResponse().setDateHeader("Expires", 0); } public String getId() { return id; } public void setId(String id) { this.id = id; } public String[] getIds() { return ids; } public void setIds(String[] ids) { this.ids = ids; } public String[] getApnids() { return apnids; } public void setApnids(String[] apnids) { this.apnids = apnids; } public String[] getPeversionids() { return peversionids; } public void setPeversionids(String[] peversionids) { this.peversionids = peversionids; } public String[] getOsversionids() { return osversionids; } public void setOsversionids(String[] osversionids) { this.osversionids = osversionids; } public String[] getAreaids() { return areaids; } public void setAreaids(String[] areaids) { this.areaids = areaids; } public String[] getDevmodelids() { return devmodelids; } public void setDevmodelids(String[] devmodelids) { this.devmodelids = devmodelids; } public String[] getAll_deviceids() { return all_deviceids; } public void setAll_deviceids(String[] allDeviceids) { all_deviceids = allDeviceids; } public Pager getPager() { return pager; } public void setPager(Pager pager) { this.pager = pager; } public String getLogInfo() { return logInfo; } public void setLogInfo(String logInfo) { this.logInfo = logInfo; } public String getRedirectionUrl() { return redirectionUrl; } public void setRedirectionUrl(String redirectionUrl) { this.redirectionUrl = redirectionUrl; } public String[] getTest_e2eboss_ids() { return test_e2eboss_ids; } public void setTest_e2eboss_ids(String[] testE2ebossIds) { test_e2eboss_ids = testE2ebossIds; } public String[] getTest_pushteam_ids() { return test_pushteam_ids; } public void setTest_pushteam_ids(String[] testPushteamIds) { test_pushteam_ids = testPushteamIds; } public String[] getTest_otherteam_ids() { return test_otherteam_ids; } public void setTest_otherteam_ids(String[] testOtherteamIds) { test_otherteam_ids = testOtherteamIds; } public String[] getA_devmodelids() { return a_devmodelids; } public void setA_devmodelids(String[] aDevmodelids) { a_devmodelids = aDevmodelids; } public String[] getP_devmodelids() { return p_devmodelids; } public void setP_devmodelids(String[] pDevmodelids) { p_devmodelids = pDevmodelids; } public String[] getS_devmodelids() { return s_devmodelids; } public void setS_devmodelids(String[] sDevmodelids) { s_devmodelids = sDevmodelids; } public String[] getK_devmodelids() { return k_devmodelids; } public void setK_devmodelids(String[] kDevmodelids) { k_devmodelids = kDevmodelids; } public String[] getLe1_devmodelids() { return le1_devmodelids; } public void setLe1_devmodelids(String[] le1Devmodelids) { le1_devmodelids = le1Devmodelids; } public String[] getOther_devmodelids() { return other_devmodelids; } public void setOther_devmodelids(String[] otherDevmodelids) { other_devmodelids = otherDevmodelids; }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:PhotoBarcode - 易于使用的库在Android应用程序中拍照或扫描条形码
下一篇:小程序指的是什么(小程序指的是什么软件)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~