⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manageservlet.java~4~

📁 jsp设计的留言板,供大家参考,使用的是文本文件作为数据库
💻 JAVA~4~
字号:
package bookservlets;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import bookutil.BookTools;
import bookutil.DataDo;
public class ManageServlet extends HttpServlet {
  private static final String CONTENT_TYPE = "text/html; charset=Big5";

  //Initialize global variables
  public void init() throws ServletException {
  }

  //Process the HTTP Get request
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    //--------right check
    BookTools bt = new BookTools();
    String name = bt.elicitCookie(request,"master").toString();
    if(name == null || name.length() == 0){
      out.println("<script>window.location=\"manage/masterlogin.jsp\"</script>");
      return;
    }
    DataDo db = new DataDo();
    int status = 0;
    //----------process delete request
    if(request.getParameter("smdelete") != null)
    {
       String id = request.getParameter("id").trim();
      try {
        status = db.dataUpdate("delete from book where g_id in ('" + id + "')");
        out.println("<script>window.alert(\""+status+" Records Victory ! \");</script>");
      }
      catch (Exception ex) {
        out.println("<script>window.alert(\" Execute SQL Error ! \");</script>");
      }
    }
    //----------process reply request
    if(request.getParameter("smreply") != null)
    {
       String id = request.getParameter("id").trim();
       String content = request.getParameter("reply").trim();
       content = new String(content.getBytes("ISO-8859-1"));
      try {
        status = db.dataUpdate("update book set g_reply='"+content+"' where g_id='" + id + "'");
        out.println("<script>window.alert(\""+status+" Records Victory ! \");</script>");
      }
      catch (Exception ex) {
        out.println("<script>window.alert(\" Execute SQL Error ! \");</script>");
      }
    }

  }

  //Process the HTTP Post request
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
  }

  //Clean up resources
  public void destroy() {
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -