資源簡介
移動學習平臺
代碼片段和文件信息
package?cn.edu.scu.mobilearn.CommonUtil;
import?java.io.IOException;
import?java.io.PrintWriter;
import?java.util.List;
import?java.util.Map;
import?javax.servlet.http.HttpServletResponse;
import?net.sf.json.JSONArray;
import?net.sf.json.JSONobject;
import?net.sf.json.JsonConfig;
import?net.sf.json.processors.JsDateJsonBeanProcessor;
import?org.apache.commons.lang.StringUtils;
public?class?CommonUtil?{
//header?常量定義//
private?static?final?String?ENCODING_PREFIX?=?“encoding“;
private?static?final?String?NOCACHE_PREFIX?=?“no-cache“;
private?static?final?String?ENCODING_DEFAULT?=?“UTF-8“;?//
private?static?final?boolean?NOCACHE_DEFAULT?=?true;
//content-type?定義?//
private?static?final?String?TEXT?=?“text/plain“;
private?static?final?String?JSON?=?“application/json“;
private?static?final?String?xml?=?“text/xml“;
private?static?final?String?HTML?=?“text/html“;
//?繞過jsp/freemaker直接輸出文本的函數?//
/**
?*?直接輸出內容的簡便函數.
?*?eg.
?*?render(“text/plain“?“hello“?“encoding:GBK“);
?*?render(“text/plain“?“hello“?“no-cache:false“);
?*?render(“text/plain“?“hello“?“encoding:GBK“?“no-cache:false“);
?*?
?*?@param?headers?可變的header數組,目前接受的值為“encoding:“或“no-cache:“默認值分別為UTF-8和true.
?*/
public?static?void?render(final?HttpServletResponse?responsefinal?String?contentType?final?String?content?final?String...?headers)?{
try?{
//分析headers參數
String?encoding?=?ENCODING_DEFAULT;
boolean?noCache?=?NOCACHE_DEFAULT;
for?(String?header?:?headers)?{
String?headerName?=?StringUtils.substringBefore(header?“:“);
String?headerValue?=?StringUtils.substringAfter(header?“:“);
if?(StringUtils.equalsIgnoreCase(headerName?ENCODING_PREFIX))?{
encoding?=?headerValue;
}?else?if?(StringUtils.equalsIgnoreCase(headerName?NOCACHE_PREFIX))?{
noCache?=?Boolean.parseBoolean(headerValue);
}?else
throw?new?IllegalArgumentException(headerName?+?“不是一個合法的header類型“);
}
//設置headers參數
String?fullContentType?=?contentType?+?“;charset=“?+?encoding;
response.setContentType(fullContentType);
if?(noCache)?{
response.setHeader(“Pragma“?“No-cache“);
response.setHeader(“Cache-Control“?“no-cache“);
response.setDateHeader(“Expires“?0);
}
PrintWriter?writer?=?response.getWriter();
writer.write(content);
writer.flush();
writer.close();
}?catch?(IOException?e)?{
e.printStackTrace();
}
}
/**
?*?直接輸出文本.
?*?@see?#render(String?String?String...)
?*/
public?static?void?renderText(final?HttpServletResponse?responsefinal?String?text?final?String...?headers)?{
render(responseTEXT?text?headers);
}
/**
?*?直接輸出HTML.
?*?@see?#render(String?String?String...)
?*/
public?static?void?renderHtml(final?HttpServletResponse?responsefinal?String?html?final?String...?headers)?{
render(responseHTML?html?headers);
}
/**
?*?直接輸出xml.
?*?@see?#render(String?String?String...)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????548??2014-07-18?15:20??mobilearn\.classpath
?????文件???????1042??2014-06-26?15:55??mobilearn\.project
?????文件????????503??2014-06-26?09:30??mobilearn\.settings\.jsdtscope
?????文件????????287??2015-04-15?12:52??mobilearn\.settings\org.eclipse.core.resources.prefs
?????文件????????364??2014-06-26?09:30??mobilearn\.settings\org.eclipse.jdt.core.prefs
?????文件????????479??2014-06-26?15:55??mobilearn\.settings\org.eclipse.wst.common.component
?????文件????????345??2014-06-26?09:30??mobilearn\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件?????????49??2014-06-26?09:30??mobilearn\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件??????????6??2014-06-26?09:30??mobilearn\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????文件????????584??2014-06-27?10:58??mobilearn\build\classes\c3p0-config.xm
?????文件???????6592??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\CommonUtil\CommonUtil.class
?????文件???????2001??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\CommonUtil\MD5.class
?????文件????????873??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\CommonUtil\Replace.class
?????文件????????579??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\BbsDao.class
?????文件????????374??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\Dao.class
?????文件????????778??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\DaoFactory.class
?????文件???????3379??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\DaoSupport.class
?????文件????????523??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\DiaryDao.class
?????文件????????496??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\DocmentDao.class
?????文件????????415??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\GradeDao.class
?????文件???????1912??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\HelpDaoImpl.class
?????文件???????3800??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\impl\BbsDaoImpl.class
?????文件???????3587??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\impl\DiaryDaoImpl.class
?????文件???????3658??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\impl\DocmentDaoImpl.class
?????文件???????3157??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\impl\GradeDaoImpl.class
?????文件???????3263??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\impl\NoticDaoImpl.class
?????文件???????3333??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\impl\RepBbsDaoImpl.class
?????文件???????3292??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\impl\TestDaoImpl.class
?????文件???????4603??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\impl\UserDaoImpl.class
?????文件???????4217??2015-05-11?12:04??mobilearn\build\classes\cn\edu\scu\mobilearn\dao\impl\VediophotoDaoImpl.class
............此處省略2959個文件信息
評論
共有 條評論