📄 generalaction.java
字号:
package cn.edu.hlju.oa.kygl.action;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.Properties;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.j2ee.servlets.ImageServlet;
import java.util.TreeMap;
import cn.edu.hlju.oa.kygl.db.DBConnection;
import java.sql.*;
/**
* 抽象的动作类,用于定义一些公用的部分
*/
public abstract class GeneralAction extends HttpServlet
{
//新更改的StyleBit*******************
protected final int ERR = 0x0001;
protected final int DEFAULT = 0x0002;
protected final int ADD = 0x0004;
protected final int DELETE = 0x0008;
protected final int MODIFY = 0x0010;
protected final int SAVE = 0x0020;
//下一页的动作
protected final int NEXT_PAGE = 0x0040; //表示分页处理
protected final int ENTRY = 0x0080; //表示单纯的进入
protected final int ADD_INVALID = 0x0100;
protected final int DELETE_INVALID = 0x0200;
protected final int MODIFY_INVALID = 0x0400;
protected final int SAVE_INVALID = 0x0800;
protected final int REPORT_QUERY = 0x1000;//表示进入报表查询页面
protected final int REPORT_PREVIEW = 0x2000;//表示进入报表生成
protected final int REPORT_PRINT = 0x4000; //要打印报表
protected final int REPORT_EXPORT = 0x8000; //要导出报表
protected final int REPORT_EXPORT_PDF = 0x8001; //导出成PDF
protected final int REPORT_EXPORT_RTF = 0x8002; //导出成RTF
protected final int REPORT_EXPORT_XLS = 0x8003; //导出成XLS
protected final int STATISTIC_ACTION= 0x10000;
protected final int STATISTIC_QUERY = 0x10001; //进入查询页面
protected final int STATISTIC_WHOLE = 0x10002; //查询整体的情况
protected final int STATISTIC_PROJECT = 0x10003; //查询整体/重点实验室的项目情况
protected final int STATISTIC_AWARD = 0x10004; //查询整体/重点实验室的获奖情况
protected final int STATISTIC_RESULT = 0x10005; //查询整体/重点实验室的成果情况
protected final int STATISTIC_ARTICLE = 0x10006; //查询整体/重点实验室的著作情况
protected final int STATISTIC_PAPER = 0x10007; //查询整体/重点实验室的论文情况
//用于记录当前的动作类型
protected int actionType;
//动作页的url
protected String actionPage;
//server的IP地址
public static String serverIPAddress;
//server的端口号
public static String serverPort;
static{
System.out.println("GereralAction user.dir="+System.getProperty("user.dir"));
System.out.println("GeneralAction catalina.base="+System.getProperty("catalina.base"));
String kyglAppPath = System.getProperty("catalina.base")+"/webapps/kygl/Config/";
Properties prop = new Properties();
try{
prop.load(new FileInputStream(new File(kyglAppPath + "SysInfo.properties")));
System.out.println("成功读取配置文件....");
}catch(Exception e){
System.err.println("GeneralAction不能正确读取配置信息,写入默认配置....");
prop.put("serverIPAddress","210.46.111.23");
prop.put("serverPort","8083");
}
serverIPAddress = prop.getProperty("serverIPAddress");
serverPort = prop.getProperty("serverPort");
}
public GeneralAction() {
//构造函数无特殊功能
}
/**
* 缺省要实现的方法
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
try{
process(request,response);
}catch(Exception e){
e.printStackTrace();
//一旦发生异常就转到错误页面
RequestDispatcher rd=request.getRequestDispatcher("Err.html");
request.setAttribute("errMsg",e.getMessage());
rd.forward(request,response);
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
protected void process(HttpServletRequest request, HttpServletResponse response)
throws Exception {
preProcess(request,response);
validate(request,response);
executeBusiniess(request,response);
reDirection(request,response);
}
/**
* 一些预处理操作
* @param request HttpServletRequest
* @param response HttpServletResponse
* @throws Exception
*/
abstract void preProcess(HttpServletRequest request, HttpServletResponse response) throws Exception;
/**
* 验证操作
* @param request HttpServletRequest
* @param response HttpServletResponse
* @throws Exception
*/
abstract void validate(HttpServletRequest request, HttpServletResponse response) throws Exception;
/**
* 执行业务逻辑的操作
* @param request HttpServletRequest
* @param response HttpServletResponse
* @throws Exception
*/
abstract void executeBusiniess(HttpServletRequest request, HttpServletResponse response) throws Exception;
/**
* 进行页面的重定向
* @param request HttpServletRequest
* @param response HttpServletResponse
* @throws Exception
*/
void reDirection(HttpServletRequest request, HttpServletResponse response) throws Exception{
RequestDispatcher rd=request.getRequestDispatcher(actionPage);
//ServletContext context = getServletContext();
//RequestDispatcher rd = context.getRequestDispatcher("/"+actionPage);
//rd.forward( request, response);
rd.forward(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -