BaseAction.java
资源名称:ssh+ext.rar [点击查看]
上传用户:ouhalaa
上传日期:2016-03-17
资源大小:10210k
文件大小:2k
源码类别:
Web服务器
开发平台:
Java
- package com.lhq.prj.bms.core;
- import java.io.IOException;
- import java.io.PrintWriter;
- 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);
- }
- }