本文整理汇总了Java中javax.servlet.ServletContext.getInitParameterNames方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContext.getInitParameterNames方法的具体用法?Java ServletContext.getInitParameterNames怎么用?Java ServletContext.getInitParameterNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.ServletContext
的用法示例。
在下文中一共展示了ServletContext.getInitParameterNames方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: contextInitialized
import javax.servlet.ServletContext; //导入方法依赖的package包/类
public void contextInitialized(ServletContextEvent sce) {
if (sce != null && sce.getServletContext() != null) {
LOGGER.info("Context initialised, loading settings.");
ServletContext context = sce.getServletContext();
Properties properties = new Properties();
Enumeration<String> names = context.getInitParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
properties.put(name, context.getInitParameter(name));
}
CoreSettings coreSettings = new CoreSettings(
properties,
URI.create(properties.getProperty(CoreSettings.TAG_SERVICE_ROOT_URL) + "/" + properties.getProperty(CoreSettings.TAG_API_VERSION)).normalize().toString(),
context.getAttribute(ServletContext.TEMPDIR).toString());
context.setAttribute(TAG_CORE_SETTINGS, coreSettings);
PersistenceManagerFactory.init(coreSettings);
MqttManager.init(coreSettings);
PersistenceManagerFactory.addEntityChangeListener(MqttManager.getInstance());
}
}
示例2: xmlConversionServiceFactoryForServlets
import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
* Factory for use in Servlets to create an XMLConversionService using
* configurations found in the Servlet context parameters. This method also
* places the path to the XSL files directory in the servlet context under
* 'xslFilesDirecoryPath', for use by the JavaXmlConverters. <p>
*
* To configure a format converter that uses an XSL style sheet or Java class,
* the context param-name must begin with the either 'xslconverter' or
* 'javaconverter' and must be unique. The param-value must be of the form
* 'xslfile.xsl|[from format]\[to format]' or '[fully qualified Java
* class]|[from format]\[to format]'.
*
* @param servletContext The ServletContext
* @param xslFilesDirecory The base directory where the XSL files are
* located
* @param xmlCachDirecory The directory where the service will cache the
* converted XML files
* @param filterDeclarations Set to true to filter out the XML and DTD
* declarations in the converted XML
* @return The XMLConversionService
* @exception Exception If error
*/
public static XMLConversionService xmlConversionServiceFactoryForServlets(
ServletContext servletContext,
File xslFilesDirecory,
File xmlCachDirecory,
boolean filterDeclarations)
throws Exception {
// Set up an XML Conversion Service:
// Place the xsl dir path in the Servlet context for use by the JavaXmlConverters
servletContext.setAttribute("xslFilesDirecoryPath", xslFilesDirecory.getAbsolutePath());
XMLConversionService xmlConversionService = null;
xmlCachDirecory.mkdir();
xmlConversionService =
new XMLConversionService(xmlCachDirecory, filterDeclarations);
// Add configured converters:
Enumeration enumeration = servletContext.getInitParameterNames();
String param;
while (enumeration.hasMoreElements()) {
param = (String) enumeration.nextElement();
if (param.toLowerCase().startsWith("xslconverter")) {
xmlConversionService.addXslConverterHelper(servletContext.getInitParameter(param), xslFilesDirecory);
}
if (param.toLowerCase().startsWith("javaconverter")) {
xmlConversionService.addJavaConverterHelper(servletContext.getInitParameter(param), servletContext);
}
}
return xmlConversionService;
}
示例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>");
}
示例4: addContextParametersToSystemProperties
import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
* Ajoute les paramètres de contexte aux propriétés systèmes, de manière à les rendre accessibles dans logback.xml
* @param servletContext
*/
private void addContextParametersToSystemProperties(ServletContext servletContext) {
Enumeration<String> e = servletContext.getInitParameterNames();
while (e.hasMoreElements()) {
String parameterName = e.nextElement();
System.setProperty("context." + parameterName, servletContext.getInitParameter(parameterName));
}
System.setProperty(ConstanteUtils.STARTUP_INIT_FLYWAY, "");
}
示例5: 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;
}
};
}