/** * Initialize logback, including setting the web app root system property. * * @param servletContext the current ServletContext * @see WebUtils#setWebAppRootSystemProperty */ public static void initLogging(ServletContext servletContext) { // Expose the web app root system property. if (exposeWebAppRoot(servletContext)) { WebUtils.setWebAppRootSystemProperty(servletContext); } // Only perform custom logback initialization in case of a config file. String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM); if (location != null) { // Perform actual logback initialization; else rely on logback's default initialization. try { // Return a URL (e.g. "classpath:" or "file:") as-is; // consider a plain file path as relative to the web application root directory. if (!ResourceUtils.isUrl(location)) { // Resolve system property placeholders before resolving real path. location = SystemPropertyUtils.resolvePlaceholders(location); location = WebUtils.getRealPath(servletContext, location); } // Write log message to server log. servletContext.log("Initializing logback from [" + location + "]"); // Initialize without refresh check, i.e. without logback's watchdog thread. LogbackConfigurer.initLogging(location); } catch (FileNotFoundException ex) { throw new IllegalArgumentException( "Invalid 'logbackConfigLocation' parameter: " + ex.getMessage()); } } }
@ModelAttribute public void frontUrl(ModelMap model, HttpServletRequest request, HttpServletResponse response) throws Exception { // model.addAttribute("frontUrl", request.getContextPath() + "/resources"); userLoad(model); model.addAttribute("frontUrl", request.getContextPath() + "/resources"); // System.out.println("xDamsController.frontUrl() multiAccount: " + multiAccount); // System.out.println("xDamsController.frontUrl() model.get(\"userBean\"): " + // model.get("userBean")); if (multiAccount && model.get("userBean") != null) { model.addAttribute( "frontUrl", request.getContextPath() + "/resources/" + ((UserBean) model.get("userBean")).getAccountRef()); } // System.out.println("xDamsController.frontUrl() model.get(\"frontUrl\"): " + // model.get("frontUrl")); model.addAttribute("contextPath", request.getContextPath()); String userAgent = ((HttpServletRequest) request).getHeader("User-Agent"); if (userAgent.toLowerCase().contains("msie")) { response.addHeader("X-UA-Compatible", "IE=edge"); } try { Locale locale = RequestContextUtils.getLocale(request); ((UserBean) model.get("userBean")).setLanguage(locale.getLanguage()); } catch (Exception e) { // TODO: handle exception } model.put("realPath", WebUtils.getRealPath(servletContext, "")); }
/** * 得到绝对路径 * * @param path * @return * @throws FileNotFoundException */ public static String getRealPath(String path) throws FileNotFoundException { return WebUtils.getRealPath(getServletContext(), path); }