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

📄 deleteemployeeaction.java

📁 USB设计的一些源码!适合与USB开发的同学!还是蛮不错的!我用过一些!
💻 JAVA
字号:
package com.wiley;import java.io.IOException;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionError;import javax.sql.DataSource;import java.sql.Connection;import java.sql.Statement;import java.sql.ResultSet;import java.sql.SQLException;public class DeleteEmployeeAction extends Action {  protected void deleteEmployee(String username)    throws Exception {    String user = null;    Connection conn = null;    Statement stmt = null;    ResultSet rs = null;    ServletContext context = servlet.getServletContext();    DataSource dataSource = (DataSource)      context.getAttribute(Action.DATA_SOURCE_KEY);    try {      conn = dataSource.getConnection();      stmt = conn.createStatement();      StringBuffer sqlString =        new StringBuffer("delete from employees ");      sqlString.append("where username='" + username + "'");      stmt.execute(sqlString.toString());    }    finally {      if (rs != null) {        rs.close();      }      if (stmt != null) {        stmt.close();      }      if (conn != null) {        conn.close();      }    }  }	public ActionForward perform(ActionMapping mapping,		ActionForm form,		HttpServletRequest request,		HttpServletResponse response)		throws IOException, ServletException {		// Default target to success    String target = new String("success");    EmployeesActionMapping employeesMapping =      (EmployeesActionMapping)mapping;    // Does this action require the user to login    if ( employeesMapping.isLoginRequired() ) {      HttpSession session = request.getSession();      if ( session.getAttribute("USER") == null ) {        // The user is not logged in        target = new String("login");        ActionErrors errors = new ActionErrors();        errors.add(ActionErrors.GLOBAL_ERROR,          new ActionError("errors.login.required"));        // Report any errors we have discovered        // back to the original form        if (!errors.empty()) {          saveErrors(request, errors);        }      }    }    try {      deleteEmployee(request.getParameter("username"));    }    catch (Exception e) {      System.err.println("Setting target to error");      target = new String("error");      ActionErrors errors = new ActionErrors();      errors.add(ActionErrors.GLOBAL_ERROR,        new ActionError("errors.database.error",        e.getMessage()));      // Report any errors      if (!errors.empty()) {        saveErrors(request, errors);      }    }	  // Forward to the appropriate View	  return (mapping.findForward(target));	}}

⌨️ 快捷键说明

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