zoukankan      html  css  js  c++  java
  • BaseAction

    package byd.core;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    // Download by http://www.codefans.net
    import javax.servlet.ServletContext;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    import org.apache.struts2.ServletActionContext;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    @SuppressWarnings("serial")
    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);
    	}
    
    	/**
    	 * ���request
    	 * 
    	 * @return
    	 */
    	public HttpServletRequest getRequest() {
    		return ServletActionContext.getRequest();
    	}
    
    	/**
    	 * ���response
    	 * 
    	 * @return
    	 */
    	public HttpServletResponse getResponse() {
    		return ServletActionContext.getResponse();
    	}
    
    	/**
    	 * ���session
    	 * 
    	 * @return
    	 */
    	public HttpSession getSession() {
    		return getRequest().getSession();
    	}
    
    	/**
    	 * ���servlet������
    	 * 
    	 * @return
    	 */
    	public ServletContext getServletContext() {
    		return ServletActionContext.getServletContext();
    	}
    
    	public String getRealyPath(String path) {
    		return getServletContext().getRealPath(path);
    	}
    }
    
     
  • 相关阅读:
    iOS之POST与GET的优缺点
    iOS之设置头像(访问系统相册、本地上传)
    iOS之清除缓存
    iOS之自动调节输入文本框的高度
    iOS之隐藏键盘的方式
    iOS之关于 srand() 和rand()
    Android Studio移除模块
    Android 弹出输入框
    webApi添加视图出现/Index.cshtml”处的视图必须派生自 WebViewPage 或 WebViewPage<TModel>。
    JSON Web Tokens简单学习
  • 原文地址:https://www.cnblogs.com/qq1988627/p/6606926.html
Copyright © 2011-2022 走看看