📄 adminservlet.java
字号:
package cwnu.com.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;
import cwnu.com.dataiud.*;
import cwnu.com.admin.*;
import cwnu.com.rentInfo.rentInfoVo;
import cwnu.com.rentInfo.setRInfoList;
import cwnu.com.saleInfo.saleInfoVo;
import cwnu.com.saleInfo.setSInfoList;
import cwnu.com.userData.*;
public class adminServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public adminServlet() {
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 {
String action = request.getParameter("action");
String aid = request.getParameter("aid");
idudata objupdate = new idudata();
setAnnounceMentList getlist = new setAnnounceMentList();
if(action.equals("update"))// 更新公告
{
String content = new String(request.getParameter("content").getBytes("ISO-8859-1"),"GBK");
//String date = request.getParameter("date");
String date="2008-7-16";
System.out.println(content);
String sqlupdate = "update AnnounceMent set content='"+content+"',announcementDate='"+date+"' where ID='"+aid+"'";
if(objupdate.iduInfo(sqlupdate))
{
JOptionPane.showMessageDialog(null, "修改成功");
ArrayList<announceMentVo> mylist = getlist.setAList("select * from AnnounceMent");
request.getSession(true).setAttribute("announceMentList", mylist);
response.sendRedirect("Jsp/administrater/admin.jsp");
}
}if(action.equals("delete"))//删除公告
{
String sqlstr = "delete from AnnounceMent where ID='"+aid+"'";
if(objupdate.iduInfo(sqlstr))
{
JOptionPane.showMessageDialog(null, "删除成功");
ArrayList<announceMentVo> mylist = getlist.setAList("select * from AnnounceMent");
request.getSession(true).setAttribute("announceMentList", mylist);
response.sendRedirect("Jsp/administrater/admin.jsp");
}
}if(action.equals("deleteuser"))//删除会员
{
String uid = request.getParameter("uid");//管理员登陆时得到用户list
String sqldeleterenInfo = "delete from RentOutAndIn where userID='"+uid+"'";
String sqldeletesaleInfo = "delete from SaleAndBuy where userID='"+uid+"'";
String Sqldelete = "delete from UserInfo where ID='"+uid+"'";
if(objupdate.iduInfo(sqldeleterenInfo)&&objupdate.iduInfo(sqldeletesaleInfo))
if(objupdate.iduInfo(Sqldelete))
{
JOptionPane.showMessageDialog(null, "删除成功");
userList ulist = new userList();
ArrayList<userInfoVo> userlist = ulist.getlist();
setSInfoList objsetlist = new setSInfoList();
ArrayList<saleInfoVo> list = objsetlist.setList("select * from SaleAndBuy");
setRInfoList rlist = new setRInfoList();
ArrayList<rentInfoVo> rinfovolist = rlist.setList("select * from RentOutAndIn");
request.getSession().setAttribute("rentList",rinfovolist);
request.getSession().setAttribute("saleList", list);
request.getSession().setAttribute("ulist", userlist);
response.sendRedirect("Jsp/administrater/userInfoManage.jsp");
}else
{
JOptionPane.showMessageDialog(null, "删除失败");
response.sendRedirect("Jsp/administrater/userInfoManage.jsp");
}else
{
JOptionPane.showMessageDialog(null, "删除失败");
response.sendRedirect("Jsp/administrater/userInfoManage.jsp");
}
}if(action.equals("insert"))//插入公告
{
String title = new String(request.getParameter("title").getBytes("ISO-8859-1"),"GBK");
String content=new String(request.getParameter("content").getBytes("ISO-8859-1"),"GBK");
// String date = request.getParameter("date");
String date = "2008-7-16";
String adminID = request.getSession().getAttribute("adminID").toString();
System.out.println("插入公告 "+title+" "+content+" "+date+" "+adminID);
String sqlinsert = "insert into AnnounceMent(AID,title,content,announcementDate) values('"+adminID+"','"+title+"','"+content+"','"+date+"')";
if(objupdate.iduInfo(sqlinsert))
{
JOptionPane.showMessageDialog(null, "添加成功");
ArrayList<announceMentVo> mylist = getlist.setAList("select * from AnnounceMent");
request.getSession(true).setAttribute("announceMentList", mylist);
response.sendRedirect("Jsp/administrater/admin.jsp");
}else
{
JOptionPane.showMessageDialog(null, "添加失败");
response.sendRedirect("Jsp/administrater/admin.jsp");
}
}
}
/**
* 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 {
this.doGet(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -