/* * 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("| " + req + " | "); } //esle display it else { out.println("" + rs.getString(columnName) + " | "); } }//end for if (oper.equals("Modify")) { out.println("Modify | "); } else if (oper.equals("Delete")) { out.println(""); } else { out.println(" | "); } out.println(" |