📄 actionservlet.java
字号:
package com.trulytech.mantis.system;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.lang.reflect.Method;
import com.trulytech.mantis.system.logWriter;
import com.trulytech.mantis.system.TimeoutException;
/**
* <p>Title: ActionServlet</p>
* <p>Description: Servlet动作类</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: trulytech</p>
* @author WangXian
* @version 1.2
*/
public class ActionServlet
extends HttpServlet {
//Initialize global variables
public final void init() throws ServletException {
super.init();
if (!Properties.getInit()) {
ServletConfig Config = getServletConfig();
ServletContext Context = Config.getServletContext();
Properties.setXMLURL(Context.getRealPath("/"));
Properties.init();
}
PerformInit();
}
/**
* doGet请求
* @param request HttpServletRequest
* @param response HttpServletResponse
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
Statement stmt = null;
boolean isCommit = false;
Connection conn = null;
String DispatchURL = "";
try {
conn = ConnManager.getConnection();
conn.setAutoCommit(false);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Properties.Fetch_Size);
stmt.setMaxRows(Properties.MaxRows);
stmt.setQueryTimeout(Properties.QueryTimeout);
SQLParser Parser = new SQLParser(stmt, request);
isCommit = false;
int tag = HasPermission(request, response, Parser);
if (tag != Permission.ERROR) { //合法用户
if (tag != Permission.DENY) { //具有相关权限
//调用PerformGet函数
DispatchURL = PerformGet(request, response, Parser);
Dispatch(request, response, DispatchURL);
}
else {
showinvalidate(request, response, Parser);
}
conn.commit();
isCommit = true;
}
else {
throw new com.trulytech.mantis.system.TimeoutException();
}
}
catch (TimeoutException e) {
logWriter.Error(e.toString() + " (" + this.getClass().getName() +
")");
handleTimeout(request, response, e);
}
catch (Exception e) {
if (e.getCause() != null) {
if (e.getCause() instanceof TimeoutException) {
logWriter.Error(e.toString() + " (" +
this.getClass().getName() +
")");
handleTimeout(request, response, (TimeoutException) e.getCause());
}
else
e = new Exception(e.getCause());
logWriter.Error(e.toString() + " (" + this.getClass().getName() +
")");
handleExp(request, response, e);
}
else if (e != null) {
if (e instanceof TimeoutException) {
logWriter.Error(e.toString() + " (" +
this.getClass().getName() +
")");
handleTimeout(request, response, (TimeoutException) e);
}
else {
logWriter.Error(e.toString() + " (" +
this.getClass().getName() +
")");
handleExp(request, response, e);
}
}
}
finally {
try {
if (stmt != null) {
stmt.close();
stmt = null;
}
}
catch (Exception e) {
logWriter.Error(e.toString() + " (" + this.getClass().getName() +
")");
}
if (conn != null) {
try {
if (!isCommit)
conn.rollback();
}
catch (Exception e) {
logWriter.Error(e.toString() + " (" + this.getClass().getName() +
")");
}
try {
ConnManager.closeConnection(conn);
}
catch (Exception e) {
logWriter.Error(e.toString() + " (" + this.getClass().getName() +
")");
}
}
}
}
/**
* dopost请求
* @param request HttpServletRequest
* @param response HttpServletResponse
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) {
Statement stmt = null;
boolean isCommit = false;
Connection conn = null;
String DispatchURL = "";
try {
conn = ConnManager.getConnection();
conn.setAutoCommit(false);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Properties.Fetch_Size);
stmt.setMaxRows(Properties.MaxRows);
stmt.setQueryTimeout(Properties.QueryTimeout);
SQLParser Parser = new SQLParser(stmt, request);
isCommit = false;
int tag = HasPermission(request, response, Parser);
if (tag != Permission.ERROR) { //合法用户
if (tag != Permission.DENY) { //具有相关权限
//调用PerformPost方法
DispatchURL = PerformPost(request, response, Parser);
Dispatch(request, response, DispatchURL);
}
else {
showinvalidate(request, response, Parser);
}
conn.commit();
isCommit = true;
}
else {
throw new com.trulytech.mantis.system.TimeoutException();
}
}
catch (TimeoutException e) {
logWriter.Error(e.toString() + " (" + this.getClass().getName() +
")");
handleTimeout(request, response, e);
}
catch (Exception e) {
if (e.getCause() != null) {
if (e.getCause() instanceof TimeoutException) {
logWriter.Error(e.toString() + " (" +
this.getClass().getName() +
")");
handleTimeout(request, response, (TimeoutException) e.getCause());
}
else
e = new Exception(e.getCause());
logWriter.Error(e.toString() + " (" + this.getClass().getName() +
")");
handleExp(request, response, e);
}
else if (e != null) {
if (e instanceof TimeoutException) {
logWriter.Error(e.toString() + " (" +
this.getClass().getName() +
")");
handleTimeout(request, response, (TimeoutException) e);
}
else {
logWriter.Error(e.toString() + " (" +
this.getClass().getName() +
")");
handleExp(request, response, e);
}
}
}
finally {
try {
if (stmt != null) {
stmt.close();
stmt = null;
}
}
catch (Exception e) {
logWriter.Error(e.toString() + " (" + this.getClass().getName() +
")");
}
if (conn != null) {
try {
if (!isCommit)
conn.rollback();
}
catch (Exception e) {
logWriter.Error(e.toString() + " (" + this.getClass().getName() +
")");
}
try {
ConnManager.closeConnection(conn);
}
catch (Exception e) {
logWriter.Error(e.toString() + " (" + this.getClass().getName() +
")");
}
}
}
}
/**
* 执行doGet操作
* @return String
* @param request 请求
* @param response response
* @param Parser SQL解析器
* @throws Exception
*/
protected String PerformGet(HttpServletRequest request,
HttpServletResponse response, SQLParser Parser) throws
Exception {
return PerformPost(request, response, Parser);
}
/**
* 执行doPost操作
* @param request HttpServletRequest 请求
* @param response HttpServletResponse response
* @param Parser SQLParser SQL解析器
* @return String
* @throws Exception
*/
protected String PerformPost(HttpServletRequest request,
HttpServletResponse response, SQLParser Parser) throws
Exception {
try {
String MethodName = com.trulytech.mantis.system.Properties.Action_Prefix +
getParameter(request,
com.trulytech.mantis.system.Properties.
Action_Tag);
Class[] cl = new Class[3];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -