package nepu.jsp.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import nepu.jsp.DAO.ProjectDAO;
import nepu.jsp.model.ProjectModel;
import java.util.*;
import java.text.*;
public class ProjectServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public ProjectServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 获取到文章列别信息列表,并跳转到frontIndex.jsp页面显示
String operate = request.getParameter("operate");
if (operate.equals("list")) {
this.getProjectlist(request, response);
}
if (operate.equals("update")) {
// 获取修改信息
this.updateProject(request, response);
}
if (operate.equals("updatePro")) {
// 修改
this.updatePro(request, response);
}
if (operate.equals("delete")) {
// 删除
this.delete(request, response);
}
if (operate.equals("muldelete")) {
// 批量删除
this.mulitDelete(request, response);
}
if (operate.equals("getAdd")) {
// 获取添加信息
this.getAdd(request, response);
}
if (operate.equals("addPro")) {
// 添加课程
this.addProject(request, response);
}
if (operate.equals("score")) {
// 评分
this.score(request, response);
}
if (operate.equals("chaxun")) {
//
this.chaxun(request, response);
}
}
// 获取文章类别列表的方法
public void getProjectlist(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 当前页码
String pageNS = request.getParameter("pageN");
int pageN = 1;
if (pageNS != null) {
pageN = Integer.parseInt(pageNS);
}
int pageSize = 5;
Integer pageNN = Integer.valueOf(pageN);
request.setAttribute("pageN", pageNN);
// 获取课题
ProjectDAO projectDAO = new ProjectDAO();
ArrayList projectList = projectDAO.getProjectList(pageN, pageSize);
request.setAttribute("projectList", projectList);
// 获取未页页码
int recordsNum = projectDAO.getPageNum();
int pageNum = (recordsNum - 1 + pageSize) / pageSize;
Integer pageNumm = Integer.valueOf(pageNum);
request.setAttribute("pageNum", pageNumm);
// 跳转
String pages = request.getParameter("pages");
if (pages == null) {
RequestDispatcher rd = request
.getRequestDispatcher("admin/ProjectList.jsp?pageN="
+ pageN);
rd.forward(request, response);
}
if (pages.equals("s")) {
String add = request.getParameter("add");
if (add != null) {
RequestDispatcher rd = request
.getRequestDispatcher("front/FrontIndex.jsp?add=1&pageN="
+ pageN);
rd.forward(request, response);
} else {
RequestDispatcher rd = request
.getRequestDispatcher("front/FrontIndex.jsp?pageN="
+ pageN);
rd.forward(request, response);
}
}
if (pages.equals("t")) {
RequestDispatcher rd = request
.getRequestDispatcher("front/FrontIndexT.jsp?pageN="
+ pageN);
rd.forward(request, response);
}
}
// 修改
public void updatePro(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String name = request.getParameter("name");
if (name != null) {
name = new String(name.getBytes("ISO-8859-1"), "gb2312");
}
String sid = request.getParameter("sid");
String tid = request.getParameter("tid");
String score = request.getParameter("score");
String describe = request.getParameter("describe");
if (describe != null) {
describe = new String(describe.getBytes("ISO-8859-1"), "gb2312");
}
ProjectModel project = new ProjectModel();
project.setPid(Integer.parseInt(id));
project.setSid(Integer.parseInt(sid));
project.setTid(Integer.parseInt(tid));
project.setPname(name);
project.setPscore(Integer.parseInt(score));
project.setPdescribe(describe);
ProjectDAO projectDAO = new ProjectDAO();
projectDAO.updatePro(project);
// 跳转
request.setAttribute("mark", "4");
// 定位
String pageNS = request.getParameter("pageN");
int pageN = 1;
if (pageNS != null) {
pageN = Integer.parseInt(pageNS);
}
this.locate(request, response, pageN);
}
// 批量删除
public void mulitDelete(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String[] projectids = request.getParameterValues("projectids");
if (projectids != null) {
ProjectDAO projectDAO = new ProjectDAO();
projectDAO.multiDelete(projectids);
request.setAttribute("mark", "1");
// 定位
String pageNS = request.getParameter("locate");
int pageN = 1;
if (pageNS != null) {
pageN = Integer.parseInt(pageNS);
}
this.locate(request, response, pageN);
} else {
request.setAttribute("mark", "0");
// 定位
String pageNS = request.getParameter("locate");
int pageN = 1;
if (pageNS != null) {
pageN = Integer.parseInt(pageNS);
}
this.locate(request, response, pageN);
}
}
// 删除
public void delete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String id = request.getParameter("id");
String[] ids = new String[1];
ids[0] = id;
ProjectDAO projectDAO = new ProjectDAO();
projectDAO.multiDelete(ids);
request.setAttribute("mark", "1");
// 定位
String pageNS = request.getParameter("pageN");
int pageN = 1;
if (pageNS != null) {
pageN = Integer.parseInt(pageNS);
}
this.locate(request, response, pageN);
}
// 定位当前页!
public void locate(HttpServletRequest request,
HttpServletResponse response, int pageNS) throws ServletException,
IOException {
// 当前页码
int pageN = 1;
if (pageNS > 0) {
pageN = pageNS;
}
int pageSize = 5;
Integer pageNN = Integer.valueOf(pageN);
request.setAttribute("pageN", pageNN);
// 获取文章类别
ProjectDAO projectDAO = new ProjectDAO();
ArrayList projectList = projectDAO.getProjectList(pageN, pageSize);
request.setAttribute("projectList", projectList);
// 获取未页页码
int recordsNum = projectDAO.getPageNum();
int pageNum = (recordsNum - 1 + pageSize) / pageSize;
Integer pageNumm = Integer.valueOf(pageNum);
request.setAttribute("pageNum", pageNumm);
// 跳转
String key = request.getParameter("key");
if (key != null) {
if (key.equals("front")) {
RequestDispatcher rd = request
.getRequestDispatcher("front/FrontIndex.jsp?mark=1");
rd.forward(request, response);
}
} else {
RequestDispatcher rd = request
.getRequestDispatcher("admin/ProjectList.jsp?pageN="
+ pageN);
rd.forward(request, response);
}
}
// 获取要更新修改课题信息
private void updateProject(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String name = (String) request.getParameter("name");
String sname = (String) request.getParameter("sname");
String tname = (String) request.getParameter("tname");
String score = (String) request.getParameter("score");
String describe = (String) request.getParameter("describe");
String sid = (String) request.getParameter("sid");
S
评论2
最新资源