下面列出了javax.servlet.jsp.JspFactory#setDefaultFactory ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Initialize Jasper.
*
* @param classes the classes.
* @param servletContext the Servlet context.
* @throws ServletException when a Servlet error occurs.
*/
@Override
public void onStartup(Set<Class<?>> classes, ServletContext servletContext)
throws ServletException {
LOGGER.fine("Initializing Jasper integration");
if (JspFactory.getDefaultFactory() == null) {
JspFactory.setDefaultFactory(new JspFactoryImpl());
}
ServletRegistration.Dynamic registration = servletContext.addServlet(
"JSP Servlet", "org.apache.jasper.servlet.JspServlet");
registration.addMapping("*.jsp");
String classpath = System.getProperty("java.class.path")
+ getClassesDirectory(servletContext)
+ getJarFiles(servletContext);
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.log(Level.FINER, "Jasper classpath is: {0}", classpath);
}
registration.setInitParameter("classpath", classpath);
registration.setInitParameter("compilerSourceVM", "1.8");
registration.setInitParameter("compilerTargetVM", "1.8");
WebApplication webApplication = (WebApplication) servletContext;
webApplication.setJspManager(new JasperJspManager());
LOGGER.fine("Initialized Jasper integration");
}
private void setupJspFactory() {
try {
if (JspFactory.getDefaultFactory() == null) {
// enforce setting the jspfactory instance as we know it here
Class clz = Class.forName("org.apache.jasper.runtime.JspFactoryImpl"); //$NON-NLS-1$
if (clz != null) {
JspFactory.setDefaultFactory((JspFactory) clz.newInstance());
}
}
} catch (Exception ex) {
}
}