當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。