1 package com.quadcap.app.dbimage; 2 3 40 41 import java.util.HashMap ; 42 43 import javax.servlet.ServletConfig ; 44 import javax.servlet.ServletException ; 45 46 import javax.servlet.http.HttpServlet ; 47 import javax.servlet.http.HttpServletRequest ; 48 import javax.servlet.http.HttpServletResponse ; 49 50 56 public class DbImageController extends HttpServlet { 57 HashMap actions = new HashMap (); 58 59 static HashMap actionClasses = new HashMap (); 60 static { 61 actionClasses.put("/load", "com.quadcap.app.dbimage.ActionLoad"); 62 } 63 64 public void init(ServletConfig config) throws ServletException { 65 super.init(config); 66 67 } 68 69 public void doPost(HttpServletRequest request, 70 HttpServletResponse response) 71 throws ServletException 72 { 73 doGet(request, response); 74 } 75 76 public void doGet(HttpServletRequest request, 77 HttpServletResponse response) 78 throws ServletException 79 { 80 try { 81 Action action = getAction(request); 82 if (action == null) { 83 response.sendError(HttpServletResponse.SC_NOT_FOUND, 84 "Not Found"); 85 } else { 86 try { 87 action.service(request, response); 88 } catch (ServletException e) { 89 throw e; 90 } 91 } 92 } catch (Throwable t) { 93 throw new ServletException (t); 94 } 95 } 96 97 Action getAction(HttpServletRequest request) throws Exception { 98 String s = request.getPathInfo(); 99 Action action = (Action)actions.get(s); 100 if (action == null) { 101 String actionClass = (String )actionClasses.get(s); 102 if (actionClass != null) { 103 Class c = Class.forName(actionClass); 104 action = (Action)c.newInstance(); 105 action.init(getServletConfig()); 106 actions.put(s, action); 107 } 108 } 109 return action; 110 } 111 } 112 | Popular Tags |