當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServlet.init方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServlet.init方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServlet.init方法的具體用法?Java HttpServlet.init怎麽用?Java HttpServlet.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServlet的用法示例。


在下文中一共展示了HttpServlet.init方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: dispatch

import javax.servlet.http.HttpServlet; //導入方法依賴的package包/類
@SuppressWarnings("nls")
public FilterResult dispatch(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
	throws ServletException, IOException
{
	String servletPath = httpRequest.getServletPath();
	MultiMatcher mappings = ensureMappings();
	ResolvedServlet resolved = mappings.matchPath(servletPath);
	if( resolved != null )
	{
		Extension ext = resolved.getExtension();
		HttpServlet servlet;
		synchronized( ext )
		{
			servlet = servletTracker.getBeanByExtension(ext);
			if( !initedServlets.contains(ext) )
			{
				initedServlets.add(ext);
				Collection<Parameter> initParams = ext.getParameters("init-param");
				servlet.init(new DummyServletConfig(context, initParams, servlet.getClass().getName()));
			}
		}

		HttpServletRequest wrappedRequest = RemappedRequest.wrap(httpRequest, httpRequest.getContextPath(),
			resolved.getServletPath(), resolved.getPathInfo());
		try
		{
			servlet.service(wrappedRequest, httpResponse);
			httpResponse.flushBuffer();
		}
		catch( SocketException se )
		{
			// What are you going to do?
		}
		return new FilterResult(wrappedRequest);

	}
	return null;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:39,代碼來源:ServletDispatcher.java

示例2: init

import javax.servlet.http.HttpServlet; //導入方法依賴的package包/類
/**
 * Initialize the filter.
 *
 * @param filterConfig filter configuration.
 * @throws ServletException thrown if the filter could not be initialized.
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    LOG.info("AtlasAuthenticationFilter initialization started");
    final FilterConfig globalConf = filterConfig;
    final Map<String, String> params = new HashMap<>();
    try {
        configuration = ApplicationProperties.get();
    } catch (Exception e) {
        throw new ServletException(e);
    }

    if (configuration != null) {
        headerProperties = ConfigurationConverter.getProperties(configuration.subset("atlas.headers"));
    }

    FilterConfig filterConfig1 = new FilterConfig() {
        @Override
        public ServletContext getServletContext() {
            if (globalConf != null) {
                return globalConf.getServletContext();
            } else {
                return nullContext;
            }
        }

        @SuppressWarnings("unchecked")
        @Override
        public Enumeration<String> getInitParameterNames() {
            return new IteratorEnumeration(params.keySet().iterator());
        }

        @Override
        public String getInitParameter(String param) {
            return params.get(param);
        }

        @Override
        public String getFilterName() {
            return "AtlasAuthenticationFilter";
        }
    };

    super.init(filterConfig1);

    optionsServlet = new HttpServlet() {
    };
    optionsServlet.init();
}
 
開發者ID:apache,項目名稱:incubator-atlas,代碼行數:55,代碼來源:AtlasAuthenticationFilter.java

示例3: execute

import javax.servlet.http.HttpServlet; //導入方法依賴的package包/類
public void execute(String path, OutputStream os, boolean isJobRequest) throws ServletException, IOException {
  try {
    ArrayList<Filter> filters = new ArrayList<Filter>();
    XSLWebFilterConfig emptyConfig = new XSLWebFilterConfig();
    
    Filter filter;
    filter = new SetCharacterEncodingFilter();
    XSLWebFilterConfig config = new XSLWebFilterConfig();
    config.addInitParameter("encoding", "UTF-8");
    filter.init(config);
    filters.add(filter);
    
    filter = new WebAppFilter();
    filter.init(emptyConfig);
    filters.add(filter);
    
    filter = new RequestSerializerFilter();
    filter.init(emptyConfig);
    filters.add(filter);
    
    filter = new PipelineGeneratorFilter();
    filter.init(emptyConfig);
    filters.add(filter);
    
    filter = new CachingFilter();
    filter.init(emptyConfig);
    filters.add(filter);
    
    HttpServlet servlet = new XSLWebServlet();
    servlet.init();
          
    XSLWebFilterChain filterChain = new XSLWebFilterChain(servlet, filters.toArray(new Filter[filters.size()]));
    
    ServletContext servletContext = Context.getInstance().getServletContext();
    
    ServletRequest request = new XSLWebHttpServletRequest(servletContext, path);
    ServletResponse response = new XSLWebHttpServletResponse(os);
    
    WebApp webApp = null;
    if (isJobRequest) {
      webApp = WebAppFilter.getWebApp(request);
      if (webApp != null) {
        webApp.incJobRequestCount();
      }
    }
    
    try {
      filterChain.doFilter(request, response);
    } finally {
      if (webApp != null) {
        webApp.decJobRequestCount();
      } 
    }
    
  } catch (Exception e) {
    logger.error("Error executing internal servlet request to \"" + path + "\"", e);
    throw e;
  }            
}
 
開發者ID:Armatiek,項目名稱:xslweb,代碼行數:60,代碼來源:InternalRequest.java


注:本文中的javax.servlet.http.HttpServlet.init方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。