67 lines
2.4 KiB
Java
67 lines
2.4 KiB
Java
|
|
package zall;
|
||
|
|
|
||
|
|
import zutil.db.DBConnection;
|
||
|
|
import zutil.log.LogUtil;
|
||
|
|
|
||
|
|
import javax.servlet.RequestDispatcher;
|
||
|
|
import javax.servlet.ServletException;
|
||
|
|
import javax.servlet.http.*;
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.sql.SQLException;
|
||
|
|
import java.util.logging.Logger;
|
||
|
|
|
||
|
|
public abstract class ZalleryServlet extends HttpServlet {
|
||
|
|
private static Logger logger = LogUtil.getLogger();
|
||
|
|
|
||
|
|
|
||
|
|
public final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
|
||
|
|
DBConnection db = null;
|
||
|
|
try {
|
||
|
|
include("header.jsp", request, response);
|
||
|
|
doGet(request, response, db = Zallery.getDB());
|
||
|
|
include("footer.jsp", request, response);
|
||
|
|
} catch (ServletException e) {
|
||
|
|
throw e;
|
||
|
|
} catch (Exception e) {
|
||
|
|
throw new ServletException(e);
|
||
|
|
} finally {
|
||
|
|
if (db != null) db.close();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void doGet(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws ServletException, SQLException, IOException {
|
||
|
|
}
|
||
|
|
|
||
|
|
public final void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
|
||
|
|
DBConnection db = null;
|
||
|
|
try {
|
||
|
|
include("header.jsp", request, response);
|
||
|
|
doPost(request, response, db = Zallery.getDB());
|
||
|
|
include("footer.jsp", request, response);
|
||
|
|
} catch (ServletException e) {
|
||
|
|
throw e;
|
||
|
|
} catch (Exception e) {
|
||
|
|
throw new ServletException(e);
|
||
|
|
} finally {
|
||
|
|
if (db != null) db.close();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void doPost(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws ServletException, SQLException, IOException {
|
||
|
|
doGet(request, response, db);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public void include(String url, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||
|
|
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/" + url);
|
||
|
|
if (dispatcher != null)
|
||
|
|
dispatcher.include(request, response);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void forward(String url, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||
|
|
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/" + url);
|
||
|
|
if (dispatcher != null)
|
||
|
|
dispatcher.forward(request, response);
|
||
|
|
}
|
||
|
|
}
|