📄 tr_certrecordservlet.java
字号:
package com.galaxy.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.galaxy.dao.CertRecordDAO;
import com.galaxy.dao.DeptInfoDAO;
import com.galaxy.dao.UserInfoDAO;
import com.galaxy.util.PageHelp;
import com.galaxy.vo.CertRecordVO;
import com.galaxy.vo.UserInfoVO;
public class TR_CertRecordServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public TR_CertRecordServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// response.setContentType("text/html");
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
String opFlag= request.getParameter("opFlag");
if("ajax".equals(opFlag)){
validatePersonID(request, response);
}
else if ("init".equals(opFlag))
{
showList(request, response);
}
else if ("Add".equals(opFlag))
{
addRecord(request, response);
}
else if("Delete".equals(opFlag))
{
delRecord(request, response);
}
/*else if("Query".equals(opFlag))
{
queryRecord(request, response);
}*/
else if("View".equals(opFlag))
{
viewRecord(request,response);
}
else if("Edit".equals(opFlag))
{
editRecord(request,response);
}
else if("Update".equals(opFlag))
{
updateRecord(request,response);
}
}
private void validatePersonID(HttpServletRequest request, HttpServletResponse response)
throws ServletException, UnsupportedEncodingException
{
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
String personID = request.getParameter("personID");
if(personID == null || "".equals((String)personID))
{
personID = "0";
}
UserInfoDAO uiDao = new UserInfoDAO();
String cond = " and u.ui_personid = " + personID ;
List userList = new ArrayList();
userList = uiDao.queryByCondition(cond);
//响应ajax请求,并向response里输入数据
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
if(userList != null && userList.size() > 0)
{
out.write("1");
}
else{
out.write("0");
}
out.close();
}
private void showList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
int currentPage=1;//当前显示的页面号
if(request.getParameter("currentPage")!=null&&!"".equals(request.getParameter("currentPage"))){
currentPage=Integer.parseInt(request.getParameter("currentPage"));
}
System.out.println(currentPage);
PageHelp pagehelp=new PageHelp();
List certlist = new ArrayList();
CertRecordDAO certdao = new CertRecordDAO();
/*certlist = certdao.queryByCondition("");
request.setAttribute("certlist", certlist);
*/
String personname = request.getParameter("personName");
String CertName = request.getParameter("CertName");
String cond = "";
if(request.getParameter("cond")!=null && !"".equals(request.getParameter("cond")))
{
cond=request.getParameter("cond");
}
if(!"".equals(personname)&&personname!=null){
cond += " and ui_realname like '%" + personname + "%'";
}
if(!"".equals(CertName)&&CertName!=null){
cond += " and cr_name like '%" + CertName + "%'";
}
int pageSize = 5;
pagehelp=certdao.getList(cond, pageSize, currentPage);
request.setAttribute("pagehelp",pagehelp);
request.getRequestDispatcher("TrainCertificateList.jsp").forward(request, response);
}
//添加记录
private void addRecord(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
CertRecordVO certVO = new CertRecordVO();
CertRecordDAO certdao = new CertRecordDAO();
UserInfoVO uiVO = new UserInfoVO();
certVO.setCrClass(request.getParameter("CrClass"));
certVO.setCrNumber(Long.parseLong(request.getParameter("CrNumber")));
certVO.setCrExtend("");
String crDateStr = request.getParameter("CrDate");
certVO.setCrDate(Date.valueOf(crDateStr));
uiVO.setUiRealname(request.getParameter("username"));
String personIDStr = request.getParameter("userPersonID");
String cond = "and ui_personid=" + personIDStr;
UserInfoDAO uidao = new UserInfoDAO();
List userList = uidao.queryByCondition(cond);
if(userList != null && userList.size() != 0)
{
uiVO = (UserInfoVO)userList.get(0);
}
certVO.setUserInfo(uiVO);
String crName = request.getParameter("CrName");
if ("0".equals(crName))
{
certVO.setCrName("java工程师");
}
else if ("1".equals(crName))
{
certVO.setCrName("c#工程师");
}
else if ("2".equals(crName))
{
certVO.setCrName(".net工程师");
}
else if ("3".equals(crName))
{
certVO.setCrName("体系架构师");
}
else if ("4".equals(crName))
{
certVO.setCrName("网络工程师");
}
else
{
certVO.setCrName("数据库工程师");
}
int i = 0;
i = certdao.addObject(certVO);
if(i !=0 )
request.getRequestDispatcher("TR_CertRecordServlet?opFlag=init").forward(request, response);
}
//删除记录
private void delRecord(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String CertRecord[] = request.getParameterValues("checkbox");
CertRecordDAO CRdao = new CertRecordDAO();
String cond = "";
for(int i = 0; i < CertRecord.length; i++)
{
cond += ","+CertRecord[i];
}
cond = cond.substring(1);
System.out.println(cond);
int j = 0;
j = CRdao.deleteObject(cond);
if(j !=0 )
{
List certlist = new ArrayList();
CertRecordDAO certdao = new CertRecordDAO();
certlist = certdao.queryByCondition("");
request.setAttribute("certlist", certlist);
request.getRequestDispatcher("TR_CertRecordServlet?opFlag=init").forward(request, response);
}
}
//查询记录
/*private void queryRecord(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
CertRecordDAO CrDao = new CertRecordDAO();
List certlist = new ArrayList();
String personname = request.getParameter("personName");
String CertName = request.getParameter("CertName");
String cond = "";
if(!"".equals(personname)){
cond += " and ui_realname like '%" + personname + "%'";
}
if(!"".equals(CertName)){
cond += " and cr_name like '%" + CertName + "%'";
}
certlist = CrDao.queryByCondition(cond);
request.setAttribute("certlist", certlist);
request.getRequestDispatcher("TrainCertificateList.jsp").forward(request, response);
}*/
//查看证书记录
private void viewRecord(HttpServletRequest request, HttpServletResponse response)
{
CertRecordDAO crDao = new CertRecordDAO();
CertRecordVO crvo = new CertRecordVO();
//String sql = request.getParameter("crID");
String cond =request.getParameter("crID");
System.out.println(cond);
crvo = (CertRecordVO)crDao.readObject(cond);
System.out.println(crvo.getCrClass());
//System.out.println("crvo:" + crvo);
request.setAttribute("crvo", crvo);
try {
request.getRequestDispatcher("TrainCertificateView.jsp").forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void editRecord(HttpServletRequest request, HttpServletResponse response) {
CertRecordDAO crDao = new CertRecordDAO();
CertRecordVO crvo = new CertRecordVO();
String cond = request.getParameter("checkbox");
System.out.println(cond);
crvo = (CertRecordVO)crDao.readObject(cond);
System.out.println("crvo:" + crvo);
request.setAttribute("crvo", crvo);
try {
request.getRequestDispatcher("TrainCertificateUpdate.jsp").forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//修改证书记录
private void updateRecord(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
CertRecordVO crvo = new CertRecordVO();
CertRecordDAO certdao = new CertRecordDAO();
UserInfoVO uiVO = new UserInfoVO();
crvo.setCrId(Long.valueOf(request.getParameter("crid")));
crvo.setCrClass(request.getParameter("CRClass"));
crvo.setCrNumber(Long.parseLong(request.getParameter("CrNumber")));
crvo.setCrExtend("");
String crDateStr = request.getParameter("CrDate");
crvo.setCrDate(Date.valueOf(crDateStr));
/*uiVO.setUiRealname(request.getParameter("username"));
String personIDStr = request.getParameter("userPersonID");
String cond = "and ui_personid=" + personIDStr;
UserInfoDAO uidao = new UserInfoDAO();
List userList = uidao.queryByCondition(cond);
if(userList != null && userList.size() != 0)
{
uiVO = (UserInfoVO)userList.get(0);
}
certVO.setUserInfo(uiVO);*/
String crName = request.getParameter("CrName");
if ("0".equals(crName))
{
crvo.setCrName("java工程师");
}
else if ("1".equals(crName))
{
crvo.setCrName("c#工程师");
}
else if ("2".equals(crName))
{
crvo.setCrName(".net工程师");
}
else if ("3".equals(crName))
{
crvo.setCrName("体系架构师");
}
else if ("4".equals(crName))
{
crvo.setCrName("网络工程师");
}
else
{
crvo.setCrName("数据库工程师");
}
int i = 0;
i = certdao.updateObject(crvo);
if(i !=0 )
request.getRequestDispatcher("TR_CertRecordServlet?opFlag=init").forward(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -