📄 role.java
字号:
package com.soft.rolemgr.control;
import java.io.IOException;
import java.io.PrintWriter;
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.soft.deptmgr.dao.DeptInfoDAO;
import com.soft.role.dao.RoleDAO;
import com.soft.vo.DepartmentInfo;
import com.soft.vo.RoleInfo;
public class Role extends HttpServlet {
/**
* Constructor of the object.
*/
public Role() {
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 {
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 {
String methodCode = request.getParameter("methodCode");
System.out.println(methodCode);
if(methodCode.equals("addRole"))
{
int roleid=Integer.parseInt(request.getParameter("roleid"));
String rolename=request.getParameter("rolename");
rolename=new String(rolename.getBytes( "ISO8859_1"), "utf-8");
int adduser=0;
int deluser=0;
int modifyuser=0;
int addmeetroom=0;
int modifymeetroom=0;
int delmeetroom=0;
int addequip=0;
int startmeet=0;
int checkmeet=0;
try{ adduser=Integer.parseInt(request.getParameter("adduser"));}catch(Exception e){}
try{ deluser=Integer.parseInt(request.getParameter("deluser"));}catch(Exception e){}
try{ modifyuser=Integer.parseInt(request.getParameter("modifyuser"));}catch(Exception e){}
try{ addmeetroom=Integer.parseInt(request.getParameter("addmeetroom"));}catch(Exception e){}
try{ modifymeetroom=Integer.parseInt(request.getParameter("modifymeetroom"));}catch(Exception e){}
try{ delmeetroom=Integer.parseInt(request.getParameter("delmeetroom"));}catch(Exception e){}
try{ addequip=Integer.parseInt(request.getParameter("addequip"));}catch(Exception e){}
try{ startmeet=Integer.parseInt(request.getParameter("startmeet"));}catch(Exception e){}
try{ checkmeet=Integer.parseInt(request.getParameter("checkmeet"));}catch(Exception e){}
RoleDAO rd=new RoleDAO();
int i = rd.addRole(roleid,rolename,adduser,deluser,modifyuser,addmeetroom,modifymeetroom,delmeetroom,addequip, startmeet,checkmeet);
if(i>0)
{
request.getSession().setAttribute("flag","succ");
request.getRequestDispatcher("add_role.jsp").forward(request,response);
}
else
{
request.getSession().setAttribute("flag","fail");
request.getRequestDispatcher("add_role.jsp").forward(request,response);
}
}
else if(methodCode.equals("modifyRole"))
{
int roleid=Integer.parseInt(request.getParameter("roleid"));
String rolename=request.getParameter("rolename");
rolename=new String(rolename.getBytes( "ISO8859_1"), "utf-8");
int adduser=0;
int deluser=0;
int modifyuser=0;
int addmeetroom=0;
int modifymeetroom=0;
int delmeetroom=0;
int addequip=0;
int startmeet=0;
int checkmeet=0;
try{ adduser=Integer.parseInt(request.getParameter("adduser"));}catch(Exception e){System.out.println(adduser);}
try{ deluser=Integer.parseInt(request.getParameter("deluser"));}catch(Exception e){}
try{ modifyuser=Integer.parseInt(request.getParameter("modifyuser"));}catch(Exception e){}
try{ addmeetroom=Integer.parseInt(request.getParameter("addmeetroom"));}catch(Exception e){}
try{ modifymeetroom=Integer.parseInt(request.getParameter("modifymeetroom"));}catch(Exception e){}
try{ delmeetroom=Integer.parseInt(request.getParameter("delmeetroom"));}catch(Exception e){}
try{ addequip=Integer.parseInt(request.getParameter("addequip"));}catch(Exception e){}
try{ startmeet=Integer.parseInt(request.getParameter("startmeet"));}catch(Exception e){}
try{ checkmeet=Integer.parseInt(request.getParameter("checkmeet"));}catch(Exception e){}
RoleDAO rd=new RoleDAO();
int i = rd.updateRole(roleid,rolename,adduser,deluser,modifyuser,addmeetroom,modifymeetroom,delmeetroom,addequip, startmeet,checkmeet);
if(i>0)
{
request.getSession().setAttribute("flag","succ");
request.getRequestDispatcher("edit_role.jsp").forward(request,response);
}
else
{
request.getSession().setAttribute("flag","fail");
request.getRequestDispatcher("edit_role.jsp").forward(request,response);
}
}
else if(methodCode.equals("search"))
{
int page=1;
int p=1;
int pagecount=1;
try{
pagecount=Integer.parseInt(request.getAttribute("pagecount").toString());
}
catch(Exception e1){}
try{
String strPage=request.getParameter("curpage");
p=Integer.parseInt(strPage);
System.out.println("当前:"+p);
}catch(Exception e){
}
if(p>1)
page=p;
System.out.println("要转到的页面"+page);
RoleDAO rd = new RoleDAO();
rd.setCurPage(page);
List lt = rd.getAllRole();
System.out.println("总页数"+rd.getPageCount());
System.out.println("总记录数"+rd.getRowsCount());
System.out.println("每页显示记录数:"+rd.getPageSize());
System.out.println("当前页记录数:"+rd.getPageRowsCount());
request.setAttribute("roleList",lt);
request.setAttribute("rowscount", rd.getPageRowsCount());
request.setAttribute("curpage",page);
request.setAttribute("pagecount",rd.getPageCount());
request.setAttribute("rowscount",rd.getPageRowsCount());
if(lt.size()>0)
{
request.getRequestDispatcher("role_list.jsp").forward(request,response);
}
else
{
request.getRequestDispatcher("role_list.jsp").forward(request,response);
}
}
else if(methodCode.equals("del"))
{
int rowscount=Integer.parseInt(request.getParameter("rowscount"));
int page=Integer.parseInt(request.getParameter("curpage"));
String roleid = request.getParameter("roleid");
if(rowscount==1)
page=page-1;
RoleDAO rd = new RoleDAO();
rd.setCurPage(page);
int i = rd.delRole(Integer.parseInt(roleid));
List lt=rd.getAllRole();
request.setAttribute("roleList",lt);
request.setAttribute("curpage", page);
request.setAttribute("pagecount",rd.getPageCount());
if(i>0)
{
request.getSession().setAttribute("flag","succ");
request.getRequestDispatcher("role_list.jsp").forward(request,response);
}
else
{
request.getSession().setAttribute("flag","fail");
request.getRequestDispatcher("role_list.jsp").forward(request,response);
}
}
else if(methodCode.equals("update"))
{
int page=Integer.parseInt(request.getParameter("curpage"));
String roleid = request.getParameter("roleid");
RoleDAO rd = new RoleDAO();
rd.setCurPage(page);
List lst=rd.getAllRole();
List lt=rd.searchRole(Integer.parseInt(roleid));
System.out.println("lt:"+lt.size());
request.setAttribute("roleInfo",(RoleInfo)lt.get(0));
request.setAttribute("roleList",lst);
request.setAttribute("pagecount",rd.getPageCount());
request.getRequestDispatcher("modify_role.jsp").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 + -