/* * Code by George Kichukov for SAS 10/27/2002 * Updated 11/24/02 - add check login - add diferent cases * This class is used to Select Requirements to be modified for any of the tables that end with _REQ * It gets all paramters (table, operation, specific record ID) and displays * all requirement records * If operation is ADD it redirects to ModifyReq * if the operation is Modify /Delete/View it displays appropriate fields * Updated 12/05/02 - add checkDelete() javascript */ package admin; import java.util.*; import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import utilities.*; public class Req extends HttpServlet { private String errorTarget = "../admin/index.jsp"; public void init(ServletConfig config) throws ServletException { super.init(config); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // If it is a get request forward to doPost() doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //name of the user String name=""; PrintWriter out = response.getWriter(); response.setContentType("text/html"); //first thing that every servlet or jsp should do is check if user is logged in HttpSession session = request.getSession(false); //if not logged in redirect to login if(session == null) { HTMLUtils.printRedirectPage(out, "You must login to the system prior to viewing this page.", errorTarget); return; } //else if logged in take the name from the session else { name=(String)session.getAttribute("user"); //if the name is null if(name == null) { HTMLUtils.printRedirectPage(out, "You must login to the system prior to viewing this page.", errorTarget); return; } } //get parameters String table =(String) request.getParameter("table"); String oper =(String) request.getParameter("oper"); String id=request.getParameter("id"); HTMLUtils.printAdminHeader(out); //display welcome message to the user out.println("

Welcome " + name + "

"); //if we are adding redirect to ModifyReq //send 0 for id if(oper.equals("Add")) { String target = "/servlet/admin.ModifyReq?id=0&oper=" + oper + "&table=" + table + "&mID=" + id; try { // Forward the request to the target named ServletContext context = getServletContext(); RequestDispatcher dispatcher = context.getRequestDispatcher(target); dispatcher.forward(request, response); } catch(ServletException e){System.err.println("ServeltException" + e.getMessage());} catch(IOException e){System.err.println("IOException" + e.getMessage());} } // oper is Modify/View/Delete else { try { ResultSet rs=null; if(id!=null) { //pass only MAJORS for MAJOR_REQ String table2=table.substring(0,table.length()-4) +"S"; ResultSet rs2 = Retriever.getRecordName(id,table2); rs2.next(); out.println("
" + rs2.getString(1)); rs2.close(); //select only the requirements for the specific major rs = Retriever.getTableID(table, id); } else { rs = Retriever.getTable(table); } //get all the fields from the table ResultSetMetaData rsmd = rs.getMetaData(); int numberOfColumns = rsmd.getColumnCount(); out.println("
" + table + "
"); //set up the table out.println(""); out.println(""); //loop through all columns to display column headings out.println(""); for(int j=1; j" + rsmd.getColumnName(j)+ ""); } out.println(""); int counter=0; //loop through all records while(rs.next()) { out.println(""); //loop through all columns for(int i=1; i" + (++counter)); //display it as a hidden field out.println(""); } //if it ends with ID e.g. MajorID, MinorID else if ((columnName.substring(columnName.length()-2, columnName.length())).equals("ID")) { //display it as a hidden field out.println(""); } //if it is a list else if ((columnName.substring(columnName.length()-4, columnName.length())).equals("List")) { // 1. parse the course list String req=RequirementParser.toCourseDisplayString(rs.getString(columnName)); out.println(""); } //esle display it else { out.println(""); } }//end for if (oper.equals("Modify")) { out.println(""); } else if (oper.equals("Delete")) { out.println(""); } else { out.println(""); } out.println(""); }//end while rs.close(); }//end try catch(SQLException e){out.println("SQLException " + e.getMessage());} }//end else HTMLUtils.printAdminFooter(out); }//end method }//end Req.java servlet
    
" + req + "" + rs.getString(columnName) + "Modify
"); out.println(""); out.println(""); out.println(""); out.println(""); out.println("