jspservlet.java
来自「这是一个法律事务所系统源码」· Java 代码 · 共 521 行 · 第 1/2 页
JAVA
521 行
// getClass().getClassLoader() returns null in JDK 1.1.6/1.1.8 if (parentClassLoader != null) { Constants.message("jsp.message.parent_class_loader_is", new Object[] { parentClassLoader.toString() }, Logger.DEBUG); } else { Constants.message("jsp.message.parent_class_loader_is", new Object[] { "<none>" }, Logger.DEBUG); } // System.out.println("JspServlet: init " + config.getServletName() ); if( loader==null ) { if( jdk12 ) { try { Class ld=Class.forName("org.apache.jasper.servlet.JasperLoader12"); loader=(JasperLoader)ld.newInstance(); } catch(Throwable t ) { t.printStackTrace(); } } if( loader==null ) loader = new org.apache.jasper.servlet.JasperLoader(); loader.setParentClassLoader(parentClassLoader); loader.setOptions(options); Object pd=context.getAttribute("org.apache.tomcat.protection_domain"); loader.setProtectionDomain( pd ); } if (firstTime) { firstTime = false; Constants.message("jsp.message.scratch.dir.is", new Object[] { options.getScratchDir().toString() }, Logger.INFORMATION ); Constants.message("jsp.message.dont.modify.servlets", Logger.INFORMATION); JspFactory.setDefaultFactory(new JspFactoryImpl()); } } private void serviceJspFile(HttpServletRequest request, HttpServletResponse response, String jspUri, Throwable exception, boolean precompile) throws ServletException, IOException { boolean isErrorPage = exception != null; JspServletWrapper wrapper = (JspServletWrapper) jsps.get(jspUri); if (wrapper == null) { wrapper = new JspServletWrapper(jspUri, isErrorPage); jsps.put(jspUri, wrapper); } wrapper.service(request, response, precompile); } boolean preCompile(HttpServletRequest request) throws ServletException { boolean precompile = false; String precom = request.getParameter(Constants.PRECOMPILE); String qString = request.getQueryString(); if (precom != null) { if (precom.equals("true")) precompile = true; else if (precom.equals("false")) precompile = false; else { // This is illegal. throw new ServletException("Can't have request parameter " + " jsp_precomile set to " + precom); } } else if (qString != null && (qString.startsWith(Constants.PRECOMPILE) || qString.indexOf("&" + Constants.PRECOMPILE) != -1)) precompile = true; return precompile; } public void service (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String includeUri = (String) request.getAttribute(Constants.INC_SERVLET_PATH); String jspUri; if (includeUri == null) jspUri = request.getServletPath(); else jspUri = includeUri;// System.out.println("JspServletWrapper: " + includeUri + " " +// jspUri + // (String) request.getAttribute(// Constants.INC_REQUEST_URI)); boolean precompile = preCompile(request); Logger jasperLog = Constants.jasperLog; if (jasperLog != null && jasperLog.matchVerbosityLevel(Logger.INFORMATION)) { jasperLog.log("JspEngine --> "+jspUri); jasperLog.log("\t ServletPath: "+request.getServletPath()); jasperLog.log("\t PathInfo: "+request.getPathInfo()); jasperLog.log("\t RealPath: " +getServletConfig().getServletContext().getRealPath(jspUri)); jasperLog.log("\t RequestURI: "+request.getRequestURI()); jasperLog.log("\t QueryString: "+request.getQueryString()); jasperLog.log("\t Request Params: "); Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); jasperLog.log("\t\t "+name+" = "+request.getParameter(name)); } } serviceJspFile(request, response, jspUri, null, precompile); } catch (RuntimeException e) { throw e; } catch (ServletException e) { throw e; } catch (IOException e) { throw e; } catch (Throwable e) { throw new ServletException(e); } // It's better to throw the exception - we don't // know if we can deal with sendError ( buffer may be // commited ) // catch (Throwable t) { // unknownException(response, t); // } } public void destroy() { if (Constants.jasperLog != null) Constants.jasperLog.log("JspServlet.destroy()", Logger.INFORMATION); Enumeration servlets = jsps.elements(); while (servlets.hasMoreElements()) ((JspServletWrapper) servlets.nextElement()).destroy(); } /* Check if we need to reload a JSP page. * * Side-effect: re-compile the JSP page. * * @param classpath explicitly set the JSP compilation path. * @return true if JSP files is newer */ boolean loadJSP(String jspUri, String classpath, boolean isErrorPage, HttpServletRequest req, HttpServletResponse res) throws JasperException, FileNotFoundException { // Loader knows how to set the right priviledges, and call // doLoadeJsp return loader.loadJSP( this,jspUri, classpath, isErrorPage, req, res ); } /* Check if we need to reload a JSP page. * * Side-effect: re-compile the JSP page. * * @param classpath explicitly set the JSP compilation path. * @return true if JSP files is newer */ protected boolean doLoadJSP(String jspUri, String classpath, boolean isErrorPage, HttpServletRequest req, HttpServletResponse res) throws JasperException, FileNotFoundException { JspServletWrapper jsw=(JspServletWrapper) jsps.get(jspUri); if( jsw==null ) { throw new JasperException("Can't happen - JspServletWrapper=null"); } // Class jspClass = (Class) loadedJSPs.get(jspUri); boolean firstTime = jsw.servletClass == null; JspCompilationContext ctxt = new JspEngineContext(loader, classpath, context, jspUri, isErrorPage, options, req, res); boolean outDated = false; Compiler compiler = ctxt.createCompiler(); try { outDated = compiler.compile(); if ( (jsw.servletClass == null) || (compiler.isOutDated()) ) { synchronized ( this ) { if ((jsw.servletClass == null) || (compiler.isOutDated() )) { outDated = compiler.compile(); } } } } catch (FileNotFoundException ex) { throw ex; } catch (JasperException ex) { throw ex; } catch (Exception ex) { throw new JasperException(Constants.getString("jsp.error.unable.compile"), ex); } // Reload only if it's outdated if((jsw.servletClass == null) || outDated) { try { if( null ==ctxt.getServletClassName() ) { compiler.computeServletClassName(); } jsw.servletClass = loader.loadClass(ctxt.getFullClassName()); //loadClass(ctxt.getFullClassName(), true); } catch (ClassNotFoundException cex) { throw new JasperException(Constants.getString("jsp.error.unable.load"), cex); } // loadedJSPs.put(jspUri, jspClass); } return outDated; } /** * Determines whether the current JSP class is older than the JSP file * from whence it came */ public boolean isOutDated(File jsp, JspCompilationContext ctxt, Mangler mangler ) { File jspReal = null; boolean outDated; jspReal = new File(ctxt.getRealPath(jsp.getPath())); File classFile = new File(mangler.getClassFileName()); if (classFile.exists()) { outDated = classFile.lastModified() < jspReal.lastModified(); } else { outDated = true; } return outDated; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?