<%

/*
 * delete.jsp
 *
 * Deletes an entry stored through EmployeeBean with the specified name.,
 * on success, the name of the deleted entry will be displayed.
 * on failure, an error message will be displayed.
 *
 */
%>
<%@ page import="bmpapp.*,java.io.*,java.util.*,javax.naming.*" %>
<%

// Make sure this page will not be cached by the browser
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-store");

// We will send error messages to System.err, for verbosity. In a real
// application you will probably not want this. We will send a few log
// messages to System.out.
PrintStream errorStream = System.err;

// If we find any fatal error, we will store it in the "error" variable. If we
// need to store the exception too, we will store it in "exception".
String error        = null;
Exception exception = null;

// We will store the key for the entry to be deleted in this variable.
String param_1 = null;
Integer empNo = null;

// We will first attempt to get the reference to EmployeeHome from the
// session. The "list.jsp" page sets this attribute in the session.
EmployeeHome home = (EmployeeHome) session.getAttribute("bmp.EmployeeHome");
if (home == null) {
   error = "No previous connection to EmployeeBean.";
} else {

   // Attempt to get parameter from the session
   param_1 = request.getParameter("EMPNO");

   // If param_1 is null, then something is definitely wrong. When this page
   // is called from "list.jsp", pk is always specified.
   if (param_1 == null) {
      error = "EmpNO not specified.";

   // Otherwise we will attempt to find and delete the entry
   } else {
      param_1 = param_1.trim();

      try {
         empNo = new Integer(param_1);
         home.remove(new EmployeePK(empNo));
      } catch (Exception e) {

         exception = e;
         error = "Caught \"" + exception.getClass().getName() +
                 "\" while attempting to remove entry with " +
                 "key \"" + empNo + "\".";
         errorStream.println(error);
         exception.printStackTrace(errorStream);
      }
   }
}

// Decide what the title will be.
String title;
if (error != null) {
   title = "Error";
} else {
   title = "bmpapp | Delete entry";
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE><%= title %></TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
<H1><%= title %></H1>

<%
   // If there was a fatal error, then display the error message
   if (error != null) {
%>

<P><BLOCKQUOTE><%= error %></BLOCKQUOTE>

<%
   // Otherwise display a message saying that the entry was deleted
   } else {
%>

<TABLE border="1" bgcolor="#FF2222">
<TR><TD><FONT color="#FFFFFF"><STRONG>Entry with key "<%= param_1 %>" deleted.</STRONG></FONT></TD></TR>
</TABLE>

<%
   } /* else */
%>

<P><TABLE border="1">
<TR><TD><A href="list.jsp">Back&nbsp;to&nbsp;list</A></TD></TR>
</TABLE>
</BODY>
</HTML>
