随笔-77  评论-5  文章-2  trackbacks-0

package com.zte.platform;

import java.io.IOException;

import javax.faces.webapp.FacesServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ZteFacesServlet extends HttpServlet
{

 private static final String INIT_PARAM_ERROR_PAGE = "errorPage";
        private Log log = LogFactory.getLog(getClass());       
       

 private FacesServlet delegate;

 private String errorPage;

 public void init(ServletConfig servletConfig) throws ServletException
 {
  delegate = new FacesServlet();
  delegate.init(servletConfig);
  errorPage = servletConfig.getInitParameter(INIT_PARAM_ERROR_PAGE);
 }

 public void destroy()
 {
  delegate.destroy();
 }

 public ServletConfig getServletConfig()
 {
  return delegate.getServletConfig();
 }

 public String getServletInfo()
 {
  return delegate.getServletInfo();
 }

 public void service(ServletRequest request, ServletResponse response)
   throws ServletException, IOException
 {
  try
  {
   delegate.service(request, response);
  } catch (Throwable e)
  {
            log.error("page exception ,redirect to error page ",e);
            try{
   redirectToErrorPage((HttpServletRequest) request,
     (HttpServletResponse) response);
            }
            catch(Exception ex)
            {
             log.error("fail to redirect to error page",ex);
             //throw new RuntimeException("fail to redirect to error page,original exceptioin is", e);
            }
  }
 }

 private void redirectToErrorPage(HttpServletRequest request,
   HttpServletResponse response) throws IOException
 {
  if (!"".equals(errorPage))
  {
   response.sendRedirect(request.getContextPath() + errorPage);
  }
 }

}


文章来源:http://stocknewbie.bokee.com/viewdiary.18876476.html
posted on 2009-05-01 10:52 huohuo 阅读(179) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: