📄 fileservlet.java
字号:
package com.trulytech.mantis.system;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import javax.servlet.http.HttpServletRequest;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.lang.reflect.Method;
/**
* <p>Title: Mantis</p>
*
* <p>Description: Upload父类</p>
*
* <p>Copyright: Copyright (c) 2002</p>
*
* <p>Company: </p>
*
* @author Wang Xian
* @version 1.0
*/
public class FileServlet
extends ActionServlet {
/**
* 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);
//初始化Upload对象
com.jspsmart.upload.SmartUpload mySmartUpload = new com.jspsmart.upload.
SmartUpload();
mySmartUpload.initialize(getServletConfig(), request, response);
//设置上载的最大值
mySmartUpload.setMaxFileSize(setUploadMaxSize());
mySmartUpload.getFiles();
mySmartUpload.upload();
FileSQLParser Parser = new FileSQLParser(stmt, request, mySmartUpload);
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();
}
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);
com.jspsmart.upload.SmartUpload mySmartUpload = new com.jspsmart.upload.
SmartUpload();
mySmartUpload.initialize(getServletConfig(), request, response);
//设置上载的最大值
mySmartUpload.setMaxFileSize(setUploadMaxSize());
mySmartUpload.getFiles();
mySmartUpload.upload();
FileSQLParser Parser = new FileSQLParser(stmt, request, mySmartUpload);
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();
}
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() +
")");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -