import java.io.BufferedReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
/**
*/
public class testConfigController extends AbstractController {
private final static Logger log = Logger
.getLogger(testConfigController .class);
protected void doRequest(HttpServletRequest req, HttpServletResponse res)
throws IOException {
try {
doRequestForward();
} catch (ECISException e) {
log.error(MessageUtils.getCodeAndMessage(EXCEPTIONSYSERROR), e);
writeError(e);
}
}
/**
*
* <p>
* Description: 对请求的方法进行转发相应的url,进行处理
* </p>
*
* @param HttpServletRequest
* req
* @throws SystemException
*/
private void doRequestForward()
throws SystemException {
String action = request.getParameter(ACTION);
if(null!=action){
action=Character.toUpperCase(action.charAt(0)) + action.substring(1);
}
if (log.isDebugEnabled()) {
log.debug(action);
}
StringBuilder sb = new StringBuilder();
sb.append(DO);
sb.append(action);
try {
if(null!=action){
invokeMethod(this, sb.toString(), null);
}
} catch (NoSuchMethodException e) {
log.error(MessageUtils.getCodeAndMessage(EXCEPTIONMETHODERROR), e);
throw new SystemException(EXCEPTIONMETHODERROR);
} catch (IllegalAccessException e) {
log.error(MessageUtils.getCodeAndMessage(EXCEPTIONFIELDERROR), e);
throw new SystemException(EXCEPTIONFIELDERROR);
} catch (InvocationTargetException e) {
log.error(MessageUtils.getCodeAndMessage(EXCEPTIONOBJECTERROR), e);
throw new SystemException(EXCEPTIONOBJECTERROR);
}
}
/**
*
* <p>
* Description: 页面得到request请求,并对请求流进行解析成String
* </p>
*
* @param HttpServletRequest
* req
* @throws SystemException
*/
private JSONObject doRequestToJson()
throws SystemException {
JSONObject json = null;
try {
BufferedReader jsonBuffer = request.getReader();
if (null != jsonBuffer) {
json = JSONObject.fromObject(IOUtils.toString(jsonBuffer));
}
} catch (IOException e) {
log.error(MessageUtils.getCodeAndMessage(EXCEPTIONIOERROR), e);
throw new SystemException(EXCEPTIONIOERROR);
}
return json;
}
/**
* <p>当前请求数据位数组格式,需要转化为JsonArray形式</p>
* @return
* @throws SystemException
*/
private JSONArray doRequestJsonToString()
throws SystemException {
JSONArray jsonArray = null;
try {
BufferedReader jsonBuffer = request.getReader();
if (null != jsonBuffer) {
jsonArray = JSONArray.fromObject(IOUtils.toString(jsonBuffer));
}
} catch (IOException e) {
log.error(MessageUtils.getCodeAndMessage(EXCEPTIONIOERROR), e);
throw new SystemException(EXCEPTIONIOERROR);
}
return jsonArray;
}
/**
* <p>判断当前启动模式,来显示调试并打印记录信息</p>
* @param strs
*/
private void printDebugLog(String... strs) {
if (log.isDebugEnabled()) {
for (String str : strs) {
log.debug("Class:" + this.getClass() + " parameter:" + str);
}
}
}
private void printDebugLog(String str) {
if (log.isDebugEnabled()) {
log.debug("Class:" + this.getClass() + " parameter:" + str);
}
}
}
通用的Servlet控制器,类似Strtus,SpringMVC
最新推荐文章于 2024-09-21 10:38:43 发布