You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2001/04/25 23:58:41 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/jasper/servlet JspServlet.java
marcsaeg 01/04/25 14:58:41
Modified: src/share/org/apache/jasper/servlet Tag: tomcat_32
JspServlet.java
Log:
Cosmetic changes only. This commit simply updates the
indentation style in preparation for committing a major
revision.
Revision Changes Path
No revision
No revision
1.3.2.5 +255 -258 jakarta-tomcat/src/share/org/apache/jasper/servlet/JspServlet.java
Index: JspServlet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/servlet/JspServlet.java,v
retrieving revision 1.3.2.4
retrieving revision 1.3.2.5
diff -u -r1.3.2.4 -r1.3.2.5
--- JspServlet.java 2001/02/22 16:36:01 1.3.2.4
+++ JspServlet.java 2001/04/25 21:58:41 1.3.2.5
@@ -96,36 +96,36 @@
class JspServletWrapper {
Servlet theServlet;
- String jspUri;
- boolean isErrorPage;
- // ServletWrapper will set this
- Class servletClass;
-
- JspServletWrapper(String jspUri, boolean isErrorPage) {
- this.jspUri = jspUri;
- this.isErrorPage = isErrorPage;
- this.theServlet = null;
- }
-
- private void load() throws JasperException, ServletException {
- try {
- // Class servletClass = (Class) loadedJSPs.get(jspUri);
- // This is to maintain the original protocol.
- destroy();
-
- theServlet = (Servlet) servletClass.newInstance();
- } catch (Exception ex) {
- throw new JasperException(ex);
- }
- theServlet.init(JspServlet.this.config);
- if (theServlet instanceof HttpJspBase) {
+ String jspUri;
+ boolean isErrorPage;
+ // ServletWrapper will set this
+ Class servletClass;
+
+ JspServletWrapper(String jspUri, boolean isErrorPage) {
+ this.jspUri = jspUri;
+ this.isErrorPage = isErrorPage;
+ this.theServlet = null;
+ }
+
+ private void load() throws JasperException, ServletException {
+ try {
+ // Class servletClass = (Class) loadedJSPs.get(jspUri);
+ // This is to maintain the original protocol.
+ destroy();
+
+ theServlet = (Servlet) servletClass.newInstance();
+ } catch(Exception ex) {
+ throw new JasperException(ex);
+ }
+ theServlet.init(JspServlet.this.config);
+ if(theServlet instanceof HttpJspBase) {
HttpJspBase h = (HttpJspBase) theServlet;
h.setClassLoader(JspServlet.this.parentClassLoader);
- }
- }
-
- private void loadIfNecessary(HttpServletRequest req, HttpServletResponse res)
- throws JasperException, ServletException, FileNotFoundException
+ }
+ }
+
+ private void loadIfNecessary(HttpServletRequest req, HttpServletResponse res)
+ throws JasperException, ServletException, FileNotFoundException
{
// First try context attribute; if that fails then use the
// classpath init parameter.
@@ -136,12 +136,12 @@
String accordingto;
- if (cp == null || cp.equals("")) {
+ if(cp == null || cp.equals("")) {
accordingto = "according to the init parameter";
cp = options.getClassPath();
- } else
+ } else
accordingto = "according to the Servlet Engine";
-
+
Constants.message("jsp.message.cp_is",
new Object[] {
accordingto,
@@ -149,37 +149,37 @@
},
Logger.INFORMATION);
- if (loadJSP(jspUri, cp, isErrorPage, req, res)
- || theServlet == null) {
+ if(loadJSP(jspUri, cp, isErrorPage, req, res)
+ || theServlet == null) {
load();
}
- }
-
- public void service(HttpServletRequest request,
- HttpServletResponse response,
- boolean precompile)
- throws ServletException, IOException, FileNotFoundException
- {
+ }
+
+ public void service(HttpServletRequest request,
+ HttpServletResponse response,
+ boolean precompile)
+ throws ServletException, IOException, FileNotFoundException
+ {
try {
loadIfNecessary(request, response);
- // If a page is to only to be precompiled return.
- if (precompile)
- return;
-
- if (theServlet instanceof SingleThreadModel) {
- // sync on the wrapper so that the freshness
- // of the page is determined right before servicing
- synchronized (this) {
- theServlet.service(request, response);
- }
- } else {
- theServlet.service(request, response);
- }
-
- } catch (FileNotFoundException ex) {
- try {
- if (insecure_TMI) {
+ // If a page is to only to be precompiled return.
+ if(precompile)
+ return;
+
+ if(theServlet instanceof SingleThreadModel) {
+ // sync on the wrapper so that the freshness
+ // of the page is determined right before servicing
+ synchronized (this) {
+ theServlet.service(request, response);
+ }
+ } else {
+ theServlet.service(request, response);
+ }
+
+ } catch(FileNotFoundException ex) {
+ try {
+ if(insecure_TMI) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,
Constants.getString
("jsp.error.file.not.found.TMI",
@@ -194,35 +194,35 @@
// Too Much Information -- ex.getMessage()
}));
}
- } catch (IllegalStateException ise) {
+ } catch(IllegalStateException ise) {
// logs are presumed to be secure, thus the TMI info can be logged
- Constants.jasperLog.log(Constants.getString
- ("jsp.error.file.not.found.TMI",
- new Object[] {
- ex.getMessage()
- }), ex,
- Logger.ERROR);
- // rethrow FileNotFoundException so someone higher up can handle
- if (insecure_TMI)
+ Constants.jasperLog.log(Constants.getString
+ ("jsp.error.file.not.found.TMI",
+ new Object[] {
+ ex.getMessage()
+ }), ex,
+ Logger.ERROR);
+ // rethrow FileNotFoundException so someone higher up can handle
+ if(insecure_TMI)
throw ex;
else
- throw new FileNotFoundException(Constants.getString
- ("jsp.error.file.not.found",
- new Object[] {
- // Too Much Information -- ex.getMessage()
- }));
- }
+ throw new FileNotFoundException(Constants.getString
+ ("jsp.error.file.not.found",
+ new Object[] {
+ // Too Much Information -- ex.getMessage()
+ }));
+ }
return;
}
- }
+ }
- public void destroy() {
- if (theServlet != null)
- theServlet.destroy();
- }
+ public void destroy() {
+ if(theServlet != null)
+ theServlet.destroy();
+ }
}
-
-
+
+
protected ServletContext context = null;
protected Hashtable jsps = new Hashtable();
// protected Hashtable loadedJSPs = new Hashtable();
@@ -232,133 +232,131 @@
protected ClassLoader parentClassLoader;
protected ServletEngine engine;
protected String serverInfo;
-
+
/** Set to true to provide Too Much Information on errors */
private final boolean insecure_TMI = false;
static boolean firstTime = true;
static boolean jdk12=false;
static {
- try {
- Class.forName( "java.security.PrivilegedAction" );
- jdk12=true;
- } catch(Throwable ex ) {
- }
+ try {
+ Class.forName( "java.security.PrivilegedAction" );
+ jdk12=true;
+ } catch(Throwable ex ) {
+ }
}
public void init(ServletConfig config)
- throws ServletException
+ throws ServletException
{
- super.init(config);
- this.config = config;
- this.context = config.getServletContext();
+ super.init(config);
+ this.config = config;
+ this.context = config.getServletContext();
this.serverInfo = context.getServerInfo();
-
- options = new EmbededServletOptions(config, context);
+
+ options = new EmbededServletOptions(config, context);
- parentClassLoader = (ClassLoader) context.getAttribute(Constants.SERVLET_CLASS_LOADER);
- if (parentClassLoader == null)
- parentClassLoader = this.getClass().getClassLoader();
-
- // getClass().getClassLoader() returns null in JDK 1.1.6/1.1.8
- if (parentClassLoader != null) {
+ parentClassLoader = (ClassLoader) context.getAttribute(Constants.SERVLET_CLASS_LOADER);
+ if(parentClassLoader == null)
+ parentClassLoader = this.getClass().getClassLoader();
+
+ // 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 {
+ } 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());
- }
+ }
+ // 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
+ 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 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
+ throws ServletException
{
boolean precompile = false;
String precom = request.getParameter(Constants.PRECOMPILE);
String qString = request.getQueryString();
-
- if (precom != null) {
- if (precom.equals("true"))
+
+ if(precom != null) {
+ if(precom.equals("true"))
precompile = true;
- else if (precom.equals("false"))
+ 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))
+ // 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
+ HttpServletResponse response)
+ throws ServletException, IOException
{
- try {
+ try {
String includeUri
- = (String) request.getAttribute(Constants.INC_SERVLET_PATH);
+ = (String) request.getAttribute(Constants.INC_SERVLET_PATH);
String jspUri;
- if (includeUri == null)
- jspUri = request.getServletPath();
+ if(includeUri == null)
+ jspUri = request.getServletPath();
else
jspUri = includeUri;
@@ -369,51 +367,50 @@
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));
- }
- }
+ 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);
- // }
+ } 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);
+ if(Constants.jasperLog != null)
+ Constants.jasperLog.log("JspServlet.destroy()", Logger.INFORMATION);
- Enumeration servlets = jsps.elements();
- while (servlets.hasMoreElements())
- ((JspServletWrapper) servlets.nextElement()).destroy();
+ Enumeration servlets = jsps.elements();
+ while(servlets.hasMoreElements())
+ ((JspServletWrapper) servlets.nextElement()).destroy();
}
@@ -425,12 +422,12 @@
* @return true if JSP files is newer
*/
boolean loadJSP(String jspUri, String classpath,
- boolean isErrorPage, HttpServletRequest req, HttpServletResponse res)
- throws JasperException, FileNotFoundException
+ 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 );
+ // 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.
@@ -441,77 +438,77 @@
* @return true if JSP files is newer
*/
protected boolean doLoadJSP(String jspUri, String classpath,
- boolean isErrorPage, HttpServletRequest req, HttpServletResponse res)
- throws JasperException, FileNotFoundException
+ 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 = null;
- synchronized(this){
- compiler = ctxt.createCompiler();
- }
-
+ 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 = null;
+ synchronized(this){
+ compiler = ctxt.createCompiler();
+ }
+
try {
outDated = compiler.isOutDated();
- if ( (jsw.servletClass == null) || outDated ) {
+ if( (jsw.servletClass == null) || outDated ) {
synchronized ( this ) {
- if ((jsw.servletClass == null) || (compiler.isOutDated() )) {
+ if((jsw.servletClass == null) || (compiler.isOutDated() )) {
outDated = compiler.compile();
}
- }
+ }
}
- } catch (FileNotFoundException ex) {
- compiler.removeGeneratedFiles();
+ } catch(FileNotFoundException ex) {
+ compiler.removeGeneratedFiles();
throw ex;
- } catch (JasperException ex) {
+ } catch(JasperException ex) {
throw ex;
- } catch (Exception ex) {
- throw new JasperException(Constants.getString("jsp.error.unable.compile"),
+ } 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;
+ // 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
- */
+ /**
+ * 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 ) {
+ Mangler mangler ) {
File jspReal = null;
- boolean outDated;
-
+ boolean outDated;
+
jspReal = new File(ctxt.getRealPath(jsp.getPath()));
File classFile = new File(mangler.getClassFileName());
- if (classFile.exists()) {
+ if(classFile.exists()) {
outDated = classFile.lastModified() < jspReal.lastModified();
} else {
outDated = true;