You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Juan A. Hernández" <ja...@dss.es> on 2000/05/22 16:41:20 UTC
Bug & fix in 'org.apache.jasper.compiler.PluginGenerator'.
Hello:
When I try to put more than one applet in a jsp page I get an error from
the jsp compiler. The generator for the 'jsp:plugin' tag generates
variables with hardcoded names like '_jspxString', '_jspxNSString' and
'i'. If I put two or more 'jsp:plugin' tags in one page this variables
are duplicated and the java compiler fails to compile the generated
code. The easy solution to this problem is to generate all the code
inside a block. In the class
'org.apache.jasper.compiler.PluginGenerator':
public class PluginGenerator {
...
public void generate (ServletWriter writer, Class phase) throws
JasperException {
writer.println("{");
// The code of the mehod as it is now.
writer.println("}");
}
...
}
This works for this generator but it is not a general solution. I think
that it would be better to generate unique names for the variables. A
method like the following could be added to the classes
'org.apache.jasper.JspEngineContext' and
'org.apache.jasper.JspCommandLineContext' (or better to a new
'org.apache.jasper.JspBaseCompilationContext'):
private int uniqueVariableNameCount = 0;
public synchronized String getUniqueVariableName () {
return "_" + uniqueVariableNameCount ++;
}
Using a method like this the class
'org.apache.jasper.compiler.PluginGenerator' could be rewritten like
this:
public class PluginGenerator {
...
private JspCompilationContext ctxt;
...
public void init (JspCompilationContext ctxt) throws JasperException
{
this.ctxt = ctxt;
...
}
public void generate (ServletWriter writer, Class phase) throws
JasperException {
...
String uniqueNameFor_jspxString = ctxt.getUniqueVariableName();
writer.print("String " + uniqueNameFor_jspxString + " = null; ");
...
}
}
Bye,
Juan A. Hernández.