1 13 package info.magnolia.cms.servlets; 14 15 import java.io.IOException ; 16 17 import javax.servlet.ServletException ; 18 import javax.servlet.http.HttpServlet ; 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 21 22 import org.apache.log4j.Logger; 23 24 25 34 public abstract class MVCServlet extends HttpServlet { 35 36 39 private static final long serialVersionUID = 222L; 40 41 private static Logger log = Logger.getLogger(MVCServlet.class); 42 43 46 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException , 47 IOException { 48 doGet(request, response); 49 } 50 51 54 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 55 56 81 try { 83 request.setCharacterEncoding("UTF-8"); } 85 catch (java.lang.IllegalStateException e) { 86 log.error("can't set character encoding for the request", e); } 88 89 response.setCharacterEncoding("UTF-8"); 92 response.setContentType("text/html; charset=UTF-8"); 94 MVCServletHandler handler = getHandler(request, response); 95 96 if (handler == null) { 97 log.error("no handler found"); return; 99 } 100 101 if (log.isDebugEnabled()) { 102 log.debug("handler: " + handler.getName()); } 104 String command = handler.getCommand(); 105 if (log.isDebugEnabled()) { 106 log.debug("calling command: " + command); } 108 String view = handler.execute(command); 109 if (log.isDebugEnabled()) { 110 log.debug("calling view: " + view); } 112 113 handler.renderHtml(view); 114 115 } 116 117 121 protected abstract MVCServletHandler getHandler(HttpServletRequest request, HttpServletResponse response); 122 } | Popular Tags |