mainbaseservlet.java
来自「一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。」· Java 代码 · 共 194 行
JAVA
194 行
package jp.co.sjts.gsession.main;
/*
* GSession偺儀乕僗僋儔僗 GSessionBaseServlet.java
* Copyright (C) 1999-2000 Japan Total System Co,LTD
* Satoru K <koni@sjts.co.jp>
*/
import java.io.IOException;
import java.io.File;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jp.co.sjts.gsession.tools.*;
abstract public class MainBaseServlet extends HttpServlet {
protected String rootDir = null;
protected String mapURL = null;
protected String mainURL = null;
protected String helpURL = null;
protected String mailerURL = null;
abstract public void GSdoPost(Hashtable hsPara,HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException;
abstract public void GSdoGet(Hashtable hsPara,HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException;
public final String getRootDir() {
return rootDir;
}
public final String getMapURL() {
return mapURL;
}
public final String getMainURL() {
return mainURL;
}
public final String getHelpURL() {
return helpURL;
}
/**
* 儊僀儔乕偑愝掕偝傟偰偄偨応崌偼丄儊僀儔乕偺 dipacher.forword() 梡偺
* URL傪曉偡丅愝掕偝傟偰偄側偄応崌偼丄null
*
* @return 儊僀儔乕偺 dipacher.forword() 梡 URL
*/
public final String getMailerURL() {
File file = new File(rootDir,"gsmail");
if(file.exists()) {
String mailer=null;
java.io.BufferedReader reader=null;
try {
reader = GSTextFile2.OpenLoad(file);
mailer = reader.readLine();
reader.close();
} catch(Exception e) {
e.printStackTrace( );
return null;
} finally {
try {
reader.close();
} catch(Exception e) {
e.printStackTrace( );
return null;
}
}
return mailer;
} else {
return null;
}
}
public final Holiday getHoliday(String yyyy) throws GSException {
return new Holiday(new File(getRootDir()),yyyy);
}
public void init() throws ServletException {
// 僨乕僞奿擺梡偺僨傿儗僋僩儕傪庢摼(椺丗"c:\DATADIR\")
rootDir = getServletContext().getInitParameter("DataDir");
if(rootDir==null)
throw new GSException("弶婜抣偺庢摼偵幐攕(僥乕僞僨傿儗僋僩儕)");
if(!rootDir.endsWith("/"))
rootDir+="/";
rootDir = rootDir.replace('/',File.separatorChar);
// 僨傿儗僋僩儕偺桳岠惈傪僠僃僢僋
try{
File file = new File(rootDir);
if(!file.exists()) // 僼傽僀儖偑懚嵼偡傞偐
if(!file.mkdirs()) // 僼傽僀儖偑懚嵼偟側偄応崌偼丄嶌惉傪帋傒傞
throw new ServletException("僨傿儗僋僩儕嶌惉偵帋傒偨偑幐攕偟傑偟偨丅");
} catch (SecurityException e) {
throw new GSException("傾僋僙僗尃僄儔乕:"+rootDir);
}
// 儅僢僾梡偺url傪庢摼
mapURL = getServletContext().getInitParameter("MapUrl");
if(mapURL==null)
throw new GSException("弶婜抣偺庢摼偵幐攕(儅僢僾倀俼俴)");
// 儊僀儞偺URL傪庢摼
mainURL = getServletContext().getInitParameter("MainUrl");
if(mainURL==null)
throw new GSException("弶婜抣偺庢摼偵幐攕(儊僀儞倀俼俴)");
// 傊儖僾偺URL傪庢摼
helpURL = getServletContext().getInitParameter("HelpUrl");
if(helpURL==null)
throw new GSException("弶婜抣偺庢摼偵幐攕(傊儖僾倀俼俴)");
mailerURL = getServletContext().getInitParameter(GSBase.INIT_PARAM_MAILURL);
}
public final void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {
res.setHeader("Pragma", "no-cache");
res.setHeader("Cache-Control","no-store");
// 僷儔儊乕僞庢摼
Hashtable hsParam = getParam(req);
GSdoGet(hsParam,req,res);
}
public final void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {
String contentType=req.getContentType();
if(req.getContentType().toLowerCase().startsWith("multipart/form-data")) {
// ContentType偑"multipart/form-data"偺帪乮僼傽僀儖揮憲
MultiParse multiParse = new MultiParse(req,res);
multiParse.parse();
Hashtable hsParam = multiParse.getHash();
GSdoPost(hsParam,req,res);
} else {
Hashtable hsParam = getParam(req);
GSdoPost(hsParam,req,res);
}
}
protected Cookie GetCookieValue(HttpServletRequest req,String cookieName) {
Cookie cookies[] = null;
Cookie cookie = null;
if((cookies = req.getCookies()) != null) {
for(int i=0;i<cookies.length;i++) {
if(cookies[i].getName().equals(cookieName)) {
synchronized(this) {
return (Cookie)cookies[i].clone();
}
}
}
}
return null;
}
// 儕僋僄僗僩僷儔儊乕僞庢摼
protected Hashtable getParam(HttpServletRequest req) throws IOException {
Hashtable hashdata = null;
Enumeration e = req.getParameterNames();
while(e.hasMoreElements()) {
if(hashdata == null)
hashdata = new Hashtable();
String name = (String)e.nextElement();
String[] values = req.getParameterValues(name);
String values2[] = null;
values2 = new String[values.length];
for(int i=0;i<values.length;i++)
values2[i] = new String(values[i].getBytes("8859_1"),"JISAutoDetect");
hashdata.put(name,values2);
}
return hashdata;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?