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


Java ServletContext.getAttributeNames方法代碼示例

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


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

示例1: cleanupAttributes

import javax.servlet.ServletContext; //導入方法依賴的package包/類
/**
 * Find all ServletContext attributes which implement {@link DisposableBean}
 * and destroy them, removing all affected ServletContext attributes eventually.
 * @param sc the ServletContext to check
 */
static void cleanupAttributes(ServletContext sc) {
	Enumeration<String> attrNames = sc.getAttributeNames();
	while (attrNames.hasMoreElements()) {
		String attrName = attrNames.nextElement();
		if (attrName.startsWith("org.springframework.")) {
			Object attrValue = sc.getAttribute(attrName);
			if (attrValue instanceof DisposableBean) {
				try {
					((DisposableBean) attrValue).destroy();
				}
				catch (Throwable ex) {
					logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex);
				}
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:ContextCleanupListener.java

示例2: initModulePrefixes

import javax.servlet.ServletContext; //導入方法依賴的package包/類
/**
 * <p>Saves a String[] of module prefixes in the ServletContext under
 * Globals.MODULE_PREFIXES_KEY.  <strong>NOTE</strong> -
 * the "" prefix for the default module is not included in this list.</p>
 *
 * @param context The servlet context.
 * @since Struts 1.2
 */
protected void initModulePrefixes(ServletContext context) {
    ArrayList prefixList = new ArrayList();

    Enumeration names = context.getAttributeNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (!name.startsWith(Globals.MODULE_KEY)) {
            continue;
        }

        String prefix = name.substring(Globals.MODULE_KEY.length());
        if (prefix.length() > 0) {
            prefixList.add(prefix);
        }
    }

    String[] prefixes = (String[]) prefixList.toArray(new String[prefixList.size()]);
    context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:ActionServlet.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: contextDestroyed

import javax.servlet.ServletContext; //導入方法依賴的package包/類
@Override
public void contextDestroyed(ServletContextEvent sce) {
  log.info("ModelManagerListener destroying");
  // Slightly paranoid; remove objects from app scope manually
  ServletContext context = sce.getServletContext();
  for (Enumeration<String> names = context.getAttributeNames(); names.hasMoreElements();) {
    context.removeAttribute(names.nextElement());
  }

  close();

  // Hacky, but prevents Tomcat from complaining that ZK's cleanup thread 'leaked' since
  // it has a short sleep at its end
  try {
    Thread.sleep(1000);
  } catch (InterruptedException ie) {
    // continue
  }
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:20,代碼來源:ModelManagerListener.java


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