当前位置: 首页>>代码示例>>Java>>正文


Java ServletContext.getInitParameter方法代码示例

本文整理汇总了Java中javax.servlet.ServletContext.getInitParameter方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContext.getInitParameter方法的具体用法?Java ServletContext.getInitParameter怎么用?Java ServletContext.getInitParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.ServletContext的用法示例。


在下文中一共展示了ServletContext.getInitParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setWebAppRootSystemProperty

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Set a system property to the web application root directory.
 * The key of the system property can be defined with the "webAppRootKey"
 * context-param in {@code web.xml}. Default is "webapp.root".
 * <p>Can be used for tools that support substition with {@code System.getProperty}
 * values, like log4j's "${key}" syntax within log file locations.
 * @param servletContext the servlet context of the web application
 * @throws IllegalStateException if the system property is already set,
 * or if the WAR file is not expanded
 * @see #WEB_APP_ROOT_KEY_PARAM
 * @see #DEFAULT_WEB_APP_ROOT_KEY
 * @see WebAppRootListener
 * @see Log4jWebConfigurer
 */
public static void setWebAppRootSystemProperty(ServletContext servletContext) throws IllegalStateException {
	Assert.notNull(servletContext, "ServletContext must not be null");
	String root = servletContext.getRealPath("/");
	if (root == null) {
		throw new IllegalStateException(
			"Cannot set web app root system property when WAR file is not expanded");
	}
	String param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM);
	String key = (param != null ? param : DEFAULT_WEB_APP_ROOT_KEY);
	String oldValue = System.getProperty(key);
	if (oldValue != null && !StringUtils.pathEquals(oldValue, root)) {
		throw new IllegalStateException(
			"Web app root system property already set to different value: '" +
			key + "' = [" + oldValue + "] instead of [" + root + "] - " +
			"Choose unique values for the 'webAppRootKey' context-param in your web.xml files!");
	}
	System.setProperty(key, root);
	servletContext.log("Set web app root system property: '" + key + "' = [" + root + "]");
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:WebUtils.java

示例2: resolvePlaceholder

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Resolves the given placeholder using the init parameters
 * and optionally also the attributes of the given ServletContext.
 * <p>Default implementation checks ServletContext attributes before
 * init parameters. Can be overridden to customize this behavior,
 * potentially also applying specific naming patterns for parameters
 * and/or attributes (instead of using the exact placeholder name).
 * @param placeholder the placeholder to resolve
 * @param servletContext the ServletContext to check
 * @param searchContextAttributes whether to search for a matching
 * ServletContext attribute
 * @return the resolved value, of null if none
 * @see javax.servlet.ServletContext#getInitParameter(String)
 * @see javax.servlet.ServletContext#getAttribute(String)
 */
protected String resolvePlaceholder(
		String placeholder, ServletContext servletContext, boolean searchContextAttributes) {

	String value = null;
	if (searchContextAttributes) {
		Object attrValue = servletContext.getAttribute(placeholder);
		if (attrValue != null) {
			value = attrValue.toString();
		}
	}
	if (value == null) {
		value = servletContext.getInitParameter(placeholder);
	}
	return value;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:ServletContextPropertyPlaceholderConfigurer.java

示例3: doGet

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		response.setContentType("text/html");
		//get the response writer
		PrintWriter out = response.getWriter();
		//initialise the servlet context
		ServletContext context = request.getServletContext();
		//get the context name
		String lname = context.getServletContextName();
		//initialise the parameters
		String a = context.getInitParameter("a");
		String b = context.getInitParameter("b");
		String c = context.getInitParameter("c");
		String d = context.getInitParameter("d");
		
		Enumeration<String> e1 = context.getInitParameterNames();
		String param_Names = "";
		//appending attr names to a string variable 
		while(e1.hasMoreElements()) {
		param_Names = param_Names + e1.nextElement()+"<br>";
		}
				//set the attribute
		context.setAttribute("x", "XXX");
		context.setAttribute("y", "YYY");
		context.setAttribute("z", "ZZZ");

		String x = (String)context.getAttribute("x");
		String y = (String)context.getAttribute("y");
		String z = (String)context.getAttribute("z");
			//get the attribute names
				Enumeration<String> e2 = context.getAttributeNames();
					String attr_Names = "";
						//appending attr names to a string variable 
					while(e2.hasMoreElements()) {
						attr_Names = attr_Names + e2.nextElement()+"<br>";
					}//while close
//html code to display
		out.println("<html>");
			out.println("<body>");
				out.println("<h3>Servlet Context Details<h3>");
					out.println("<table border='1'>");
						out.println("<tr><td colspan='2'>Parameters Details</td></tr>");
							out.println("<tr><td>a</td><td>"+a+"</td></tr>");
							out.println("<tr><td>b</td><td>"+b+"</td></tr>");
							out.println("<tr><td>c</td><td>"+c+"</td></tr>");
							out.println("<tr><td>d</td><td>"+d+"</td></tr>");
								out.println("<tr><td>Parameter Names</td><td>"+param_Names+"</td></tr>");
									out.println("<tr><td colspan='2'>Attributes Details</td></tr>");
										out.println("<tr><td>x</td><td>"+x+"</td></tr>");
										out.println("<tr><td>y</td><td>"+y+"</td></tr>");
										out.println("<tr><td>z</td><td>"+z+"</td></tr>");
											out.println("<tr><td>Attributes Names</td><td>"+attr_Names+"</td></tr>");
												out.println("<tr><td>Logical Name</td><td>"+lname+"</td></tr>");
												out.println("<tr><td>Foreign Context</td><td>"+context.getContext("/app8")+"</td></tr>");
												out.println("</table></body></html>");

		}
 
开发者ID:pratikdimble,项目名称:Servlet_Context_Interface,代码行数:61,代码来源:ContextServlet.java

示例4: getInitParameterOrDefault

import javax.servlet.ServletContext; //导入方法依赖的package包/类
private static String getInitParameterOrDefault(ServletContext context, String propertyName, String defaultValue) {
    String base = context.getInitParameter(propertyName);
    if (base == null || base.trim().isEmpty()) {
        base = defaultValue;
    }
    return base;
}
 
开发者ID:EricssonResearch,项目名称:scott-eu,代码行数:8,代码来源:ServletListener.java

示例5: configureAndRefreshWebApplicationContext

import javax.servlet.ServletContext; //导入方法依赖的package包/类
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) {
	if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
		// The application context id is still set to its original default value
		// -> assign a more useful id based on available information
		String idParam = sc.getInitParameter(CONTEXT_ID_PARAM);
		if (idParam != null) {
			wac.setId(idParam);
		}
		else {
			// Generate default id...
			wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
					ObjectUtils.getDisplayString(sc.getContextPath()));
		}
	}

	wac.setServletContext(sc);
	String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM);
	if (configLocationParam != null) {
		wac.setConfigLocation(configLocationParam);
	}

	// The wac environment's #initPropertySources will be called in any case when the context
	// is refreshed; do it eagerly here to ensure servlet property sources are in place for
	// use in any post-processing or initialization that occurs below prior to #refresh
	ConfigurableEnvironment env = wac.getEnvironment();
	if (env instanceof ConfigurableWebEnvironment) {
		((ConfigurableWebEnvironment) env).initPropertySources(sc, null);
	}

	customizeContext(sc, wac);
	wac.refresh();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:ContextLoader.java

示例6: getXFormFilesAndIndex

import javax.servlet.ServletContext; //导入方法依赖的package包/类
private void getXFormFilesAndIndex(ServletContext context) {
	if (index == null)
		index = (SimpleLuceneIndex) context.getAttribute("index");
	if (adn_to_nsdl_file == null)
		adn_to_nsdl_file = new File(((String) context.getAttribute("xslFilesDirecoryPath")) +
			"/" + context.getInitParameter("adn-to-nsdl-dc-xsl"));
	if (namespace_out_file == null)
		namespace_out_file = new File(((String) context.getAttribute("xslFilesDirecoryPath")) +
			"/" + context.getInitParameter("namespace-out-xsl"));
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:11,代码来源:ADNToNSDLDCFormatConverter.java

示例7: contextInitialized

import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
	ServletContext context = sce.getServletContext();
	try {
		String tangyuanResource = context.getInitParameter("tangyuan.resource");
		if (null != tangyuanResource) {
			TangYuanContainer.getInstance().start(tangyuanResource);
		}
	} catch (Throwable e) {
		log.error(null, e);
		throw new TangYuanException(e);
	}
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:14,代码来源:TangYuanContextLoaderListener.java

示例8: getXFormFilesAndIndex

import javax.servlet.ServletContext; //导入方法依赖的package包/类
protected void getXFormFilesAndIndex(ServletContext context){
	if(index == null)
		index = (SimpleLuceneIndex)context.getAttribute("index");
	if(transform_file == null)
		transform_file = new File(((String) context.getAttribute("xslFilesDirecoryPath")) +
			"/" + context.getInitParameter("ncs-collect-to-nsdl-dc-xsl"));
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:8,代码来源:NCS_COLLECTToNSDL_DCFormatConverter.java

示例9: getXFormFilesAndIndex

import javax.servlet.ServletContext; //导入方法依赖的package包/类
protected void getXFormFilesAndIndex(ServletContext context) {
	String xslt = "library_dc-v1.1-to-oai_dc.xsl";
	if (context == null) {
		String xsl_dir = "C:/Documents and Settings/ostwald/devel/projects/dcs-project/web/WEB-INF/xsl_files";
		this.library_dc_to_oai_dc_transform_file = new File(xsl_dir, xslt);
	}
	else {
		this.library_dc_to_oai_dc_transform_file = new File(((String) context.getAttribute("xslFilesDirecoryPath")) +
			"/" + context.getInitParameter("library_dc-v1.1-to-oai_dc-xsl"));
	}
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:12,代码来源:LIBRARY_DCToNSDL_DCFormatConverter.java

示例10: getXFormFilesAndIndex

import javax.servlet.ServletContext; //导入方法依赖的package包/类
private void getXFormFilesAndIndex(ServletContext context){
	if(index == null)
		index = (SimpleLuceneIndex)context.getAttribute("index");
	if(adn_to_oai_file == null)
		adn_to_oai_file = new File(((String) context.getAttribute("xslFilesDirecoryPath")) +
			"/" + context.getInitParameter("adn-to-oai-dc-xsl"));
	if(namespace_out_file == null)
		namespace_out_file = new File(((String) context.getAttribute("xslFilesDirecoryPath")) +
			"/" + context.getInitParameter("namespace-out-xsl"));				
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:11,代码来源:ADNToOAIDCFormatConverter.java

示例11: setServletContext

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 *  Sets the servletContext attribute of the SmileEventListener object and
 initializes the smileMoveEventUrl.
 *
 *@param  servletContext  The new servletContext value
 */
public void setServletContext(ServletContext servletContext) {
	super.setServletContext(servletContext);
	try {
		smileMoveEventUrl = new URL((String) servletContext.getInitParameter("smileMoveEventUrl"));
	} catch (Throwable t) {
		prtlnErr("SmileEventLister could not be instantiated: " + t.getMessage());
	}
	prtln("instantiated with url: " + smileMoveEventUrl);
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:16,代码来源:SmileEventListener.java

示例12: findMacSecret

import javax.servlet.ServletContext; //导入方法依赖的package包/类
private static byte[] findMacSecret(ServletContext ctx, String algorithm)
{
    String secret = ctx.getInitParameter(INIT_MAC_SECRET);
    
    if (secret == null)
    {
        secret = ctx.getInitParameter(INIT_MAC_SECRET.toLowerCase());
    }
    
    return findMacSecret(secret, algorithm);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:12,代码来源:StateUtils.java

示例13: init

import javax.servlet.ServletContext; //导入方法依赖的package包/类
public void init() {
    // reads SMTP server setting from web.xml file
    ServletContext context = getServletContext();
    host = context.getInitParameter("host");
    port = context.getInitParameter("port");
    user = context.getInitParameter("user");
    pass = context.getInitParameter("pass");
}
 
开发者ID:stppy,项目名称:spr,代码行数:9,代码来源:EmailSendingServlet.java

示例14: createInitParamMap

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 *
 * Creates the Map that maps init parameter name to single init
 * parameter value.
 **/
public static Map<String, String> createInitParamMap(PageContext pContext)
{
  final ServletContext context = pContext.getServletContext ();
  return new EnumeratedMap<String, String> ()
    {
      public Enumeration<String> enumerateKeys () 
      {
        return context.getInitParameterNames ();
      }

      public String getValue (Object pKey) 
      {
        if (pKey instanceof String) {
          return context.getInitParameter ((String) pKey);
        }
        else {
          return null;
        }
      }

      public boolean isMutable ()
      {
        return false;
      }
    };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:ImplicitObjectELResolver.java

示例15: init

import javax.servlet.ServletContext; //导入方法依赖的package包/类
@PostConstruct
protected void init(ServletContext servletContext) {
    Client client = ClientBuilder.newClient();
    String attr = servletContext.getInitParameter("env");
    String hostIp = API_URL;
    if (attr != null && attr.equalsIgnoreCase("prod")) {
        hostIp = LOCAL_API_URL;
    }
    webTarget = client.target(hostIp);
}
 
开发者ID:slidewiki,项目名称:auto-questions-service,代码行数:11,代码来源:DBPediaSpotlightClient.java


注:本文中的javax.servlet.ServletContext.getInitParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。