List of usage examples for javax.servlet ServletContext getServletContextName
public String getServletContextName();
From source file:net.big_oh.common.web.listener.session.SimpleSessionTrackingListener.java
private static String getKeyForServletContext(ServletContext servletContext) { if (servletContext.getServletContextName() == null || "".equals(servletContext.getServletContextName())) { logger.warn("No servletContextName defined."); return "undefined"; } else {/* w w w.ja v a 2 s. c o m*/ return servletContext.getServletContextName(); } }
From source file:net.sourceforge.stripes.integration.spring.SpringHelper.java
/** * Injects Spring managed beans using a Web Application Context derived from * the ServletContext.//from w w w . j a v a 2s. c om * * @param bean the object to have beans injected into * @param ctx the ServletContext to use to find the Spring ApplicationContext */ public static void injectBeans(Object bean, ServletContext ctx) { ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(ctx); if (ac == null) { final String name = ctx.getServletContextName(); throw new IllegalStateException( "No Spring application context was found in servlet context \"" + name + "\""); } injectBeans(bean, ac); }
From source file:fr.paris.lutece.portal.service.spring.SpringContextService.java
/** * Returns a name for this context/*from w ww.j a va2 s . com*/ * @param servletContext the servlet context * @return name for this context */ private static String getContextName(ServletContext servletContext) { String name = "lutece"; if (servletContext != null) { String contextName = servletContext.getServletContextName(); if (contextName == null) { contextName = servletContext.getContextPath(); } if (StringUtils.isNotBlank(contextName)) { name = contextName; } } return name; }
From source file:org.artifactory.util.HttpUtils.java
public synchronized static String getContextId(ServletContext servletContext) { //If running servlet API 2.4, just return the servlet context name if (SERVLET_24) { return servletContext.getServletContextName(); }/*w w w . j a v a 2s . co m*/ //If running v2.5, return proper context path String contextUniqueName = PathUtils.trimLeadingSlashes(servletContext.getContextPath()); contextUniqueName = StringUtils.capitalize(contextUniqueName); return contextUniqueName; }
From source file:fr.xebia.springframework.jmx.ServletContextAwareObjectNamingStrategy.java
public void setServletContext(ServletContext servletContext) { this.servletContextName = servletContext.getServletContextName(); }
From source file:com.xhsoft.framework.common.listener.ApplicationContextListener.java
public void contextInitialized(ServletContextEvent event) { try {//w w w .j a v a 2 s . c o m ApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(event.getServletContext()); ServletContext sc = event.getServletContext(); String appName = sc.getServletContextName(); logger.info("[" + appName + "] init context ..."); AppServiceHelper.setApplicationContext(applicationContext); logger.info(" - Put Spring Context to AppServiceHelper"); String facility = sc.getInitParameter("facility"); AppContext.addParam(AppContext.FACILITY, facility); logger.info(" - Put FACILITY[" + facility + "] to AppContext"); logger.info("[" + appName + "] init context[done]"); } catch (Exception e) { logger.error("error detail:", e); } }
From source file:WebAppProperties.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); ServletContext context = getServletContext(); String displayName = context.getServletContextName(); if (displayName == null) { displayName = "(no display-name element defined)"; }/*from ww w.jav a2 s . co m*/ out.println("<html>"); out.println("<body>"); out.println("<br>Name: " + displayName); out.println("<br>Context: " + req.getContextPath()); out.println("<h2><center>"); out.println("Initialization Parameters</center></h2>"); out.println("<br>"); out.println("<center><table>"); Enumeration e = context.getInitParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println("<tr>"); out.println("<td>" + name + "</td>"); out.println("<td>" + context.getInitParameter(name) + "</td>"); out.println("</tr>"); } out.println("</table></center>"); out.println("</body>"); out.println("</html>"); out.flush(); }
From source file:com.geodan.ngr.serviceintegration.listener.ApplicationListener.java
public void contextInitialized(ServletContextEvent servletContextEvent) { log.debug("context initializing.."); ServletContext servletContext = servletContextEvent.getServletContext(); String ctxName = servletContext.getServletContextName(); String realP = servletContext.getRealPath(ctxName); String fixedRealPath = realP.substring(0, realP.lastIndexOf(ctxName)); log.debug("realpath: " + fixedRealPath); RealPath.init(fixedRealPath);/*from ww w.j a va 2 s . c o m*/ log.debug("context initialized"); }
From source file:WebAppProperties.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); ServletContext context = getServletContext(); String displayName = context.getServletContextName(); if (displayName == null) { displayName = "(no display-name element defined)"; }//from w w w.j a va 2 s .c o m out.println("<html>"); out.println("<head>"); out.println("<title>Web Application Properties"); out.println("</title>"); out.println("</head><body>"); out.println("<h1>Web Application Properties</h2>"); out.println("<br>Name: " + displayName); out.println("<br>Context: " + req.getContextPath()); out.println("<h2><center>"); out.println("Initialization Parameters</center></h2>"); out.println("<br>"); out.println("<center><table border width=80%>"); Enumeration e = context.getInitParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println("<tr>"); out.println("<td>" + name + "</td>"); out.println("<td>" + context.getInitParameter(name) + "</td>"); out.println("</tr>"); } out.println("</table></center>"); out.println("</body>"); out.println("</html>"); out.flush(); }
From source file:com.liferay.portal.servlet.SharedServletWrapper.java
public void init(ServletConfig sc) throws ServletException { super.init(sc); ServletContext ctx = getServletContext(); _servletContextName = StringUtil.replace(ctx.getServletContextName(), StringPool.SPACE, StringPool.UNDERLINE);//from w w w.j av a 2 s. c o m _servletClass = sc.getInitParameter("servlet-class"); ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { _servletInstance = (Servlet) contextClassLoader.loadClass(_servletClass).newInstance(); } catch (ClassNotFoundException cnfe) { throw new ServletException(cnfe.getMessage()); } catch (IllegalAccessException iae) { throw new ServletException(iae.getMessage()); } catch (InstantiationException ie) { throw new ServletException(ie.getMessage()); } if (_servletInstance instanceof HttpServlet) { _httpServletInstance = (HttpServlet) _servletInstance; _httpServletInstance.init(sc); } else { _servletInstance.init(sc); } }