?? dlog_actionservlet.java
字號:
/*
* DLOG_ActionServlet.java
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Winter Lau
* http://dlog4j.sourceforge.net
*
*/
package com.liusoft.dlog4j.servlet;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.SqlDateConverter;
import org.apache.commons.beanutils.converters.SqlTimestampConverter;
import org.apache.struts.action.ActionServlet;
import com.liusoft.dlog4j.DLOGSecurityManager;
import com.liusoft.dlog4j.DLOGUserManager;
import com.liusoft.dlog4j.DLOG_CacheManager;
import com.liusoft.dlog4j.Globals;
import com.liusoft.dlog4j.util.RequestUtils;
/**
* 對Struts進行擴展,實現Hibernate的初始化以及參數編碼的自動處理
* @author liudong
*/
public class DLOG_ActionServlet extends ActionServlet {
private String encoding;
static {
ConvertUtils.register(new SqlDateConverter(null), java.sql.Date.class);
ConvertUtils.register(new SqlTimestampConverter(null), java.sql.Timestamp.class);
}
/**
* Globals.WEBAPP_PATH變量值對使用access數據庫來說非常重要,涉及一個相對路徑的問題
*/
public void init() throws ServletException {
ServletContext context = getServletContext();
if (Globals.WEBAPP_PATH == null)
Globals.WEBAPP_PATH = context.getRealPath("");
//初始化系統安全控制
try {
DLOGSecurityManager.init(context);
} catch (IOException e) {
throw new ServletException(e);
}
//初始化用戶資料管理接口
try {
DLOGUserManager.init(context);
} catch (Exception e) {
throw new ServletException(e);
}
//執行Struts的初始化過程
super.init();
encoding = getInitParameter("encoding");
if(encoding==null)
encoding = Globals.ENC_UTF_8;
}
/**
* 實現對編碼的自動轉碼處理
* @param req
* @param res
* @throws ServletException
* @throws IOException
* @see org.apache.struts.action.ActionServlet#process(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void process(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
HttpServletRequest request;
if (RequestUtils.isMultipart(req)) {
//文件表單的編碼處理
request = req;
request.setCharacterEncoding(encoding);
} else {
//自動編碼處理
String enc = req.getCharacterEncoding();
if (req instanceof RequestProxy)
request = req;
else if (encoding.equalsIgnoreCase(enc))
request = req;
else
request = new RequestProxy(req, encoding);
}
super.process(request, res);
}
public void destroy() {
//釋放緩存管理器
DLOG_CacheManager.shutdown();
DLOGSecurityManager.destroy();
DLOGUserManager.destroy();
//釋放Struts
super.destroy();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -