当前位置: 首页>>代码示例>>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;未经允许,请勿转载。