Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running tag library from older Tomcat version

First some background.

I am developing a web application. This application is installed as an extension of a third party commercial web application. The thrid party provides an SDK for our application to interact with the main web application. As such, we have no control over the environment in which our application runs. We are at the mercy of the third party application.

Now for the problem.

Our application packages a custom tag library used by our JSPs. It is a requirement of the third party application that we ship only precompiled JSPs. We have no problem compiling the JSPs along with the necessary .tag files.

The third party has come out with a new version of their software. We are to support a smooth upgrade of our extension from the old version of their software to the new version.

The old version of the third party software runs on top of Tomcat 5.5. Our JSPs are built using the tomcat 5.5 JSP compiler. The new version runs on Tomcat 7. After the upgrade, our extension still runs except the tags are not evaluated correctly.

The tags emit the correct HTML however, any attributes passed to the tags seem to be lost.

As an example, I created a simple test tag:

<%@ attribute name="testValue" required="true" %>

<div name="${testValue}" >
    ${testValue}
</div>

This is used in the JSP as such:

<my:testDiv testValue="myNewTestValue" />

On Tomcat 5.5, it is evaluated and produces the following:

<div name="myNewTestValue" >
    myNewTestValue
</div>

However, the same code when run Tomcat 7, the HTML is output, but the attribute is not. Note that ${testValue} is processed but replaced with an empty value, not the value that was given.

<div name="" >

</div>

If I compile the same code using the Tomcat 7 compiler, it works again.

<div name="myNewTestValue" >
    myNewTestValue
</div>

Obviously, the version built with the Tomcat 7 JSP compiler won't run on the old version. Given the Tomcat 5.5 build won't run on the new version we don't have a smooth transition.

I've been poking around for a few weeks online trying to find a mention of this issue or even something similar and have come up with little. At least nothing that has lead me to a solution.

Is there a known issue running tags compiled with the Tomcat 5.5 compiler on Tomcat 7? Is there some magic incantation I need to chant?

Some additional info:

We are building with Maven. The relevant portions of the pom:

        <!-- Precompile JSPs -->
<!--    <dependency> -->
<!--        <groupId>org.apache.tomcat</groupId> -->
<!--        <artifactId>tomcat-jasper</artifactId> -->
<!--        <version>7.0.21</version> -->
<!--        <scope>compile</scope> -->
<!--    </dependency> -->
    <dependency>
        <groupId>tomcat</groupId>
        <artifactId>jasper-compiler</artifactId>
        <version>5.5.23</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>tomcat</groupId>
        <artifactId>jasper-runtime</artifactId>
        <version>5.5.23</version>
        <scope>compile</scope>
    </dependency>

Built using the antrun plugin:

<execution>
    <id>compile-jspc</id>
    <phase>compile</phase>
    <configuration>
        <target>
            <taskdef classname="org.apache.jasper.JspC" name="jasper">
                <classpath>
                    <pathelement location="${env.JAVA_HOME}\lib\tools.jar"/>
                    <path refid="maven.compile.classpath" />
                </classpath>
            </taskdef>
            <jasper
                caching="false"
                verbose="0"
                uriroot="${project.build.directory}/jsp"
                webXmlFragment="${project.build.directory}/generated_web.xml"
                outputDir="${project.build.directory}/jspc_out" />
        </target>
    </configuration>
    <goals>
        <goal>run</goal>
    </goals>
</execution>
<execution>
    <id>compile-jspc-java</id>
    <phase>compile</phase>
    <configuration>
        <target>
            <javac fork="true" executable="${env.JAVA_HOME}/bin/javac"
                srcdir="${project.build.directory}/jspc_out" destdir="${project.build.directory}/classes"
                deprecation="false" optimize="true">
                <classpath refid="maven.compile.classpath" />
            </javac>
        </target>
    </configuration>
    <goals>
        <goal>run</goal>
    </goals>
</execution>
like image 837
Dave Rager Avatar asked Apr 25 '14 20:04

Dave Rager


1 Answers

I think the best thing to do is probably install a Tomcat 7 test box and put your application on it as is. Get it working on 7 and then replace even the production box of the old version with Tomcat 7. When I did that, I also had an issue with tags moving from Tomcat 5.5 to Tomcat 7, but a simpler one.

I had to change:

<jsp:param name="UserID" value="<%=request.getParameter("UserID")%>" />

to:

<jsp:param name="UserID" value='<%=request.getParameter("UserID")%>' />

Double quotes to single where I was printing a request parameter into an attribute value and obviously had to use double quotes in the code inside the attribute value. Either way works in Tomcat 5.5, but only the second works in 7.

like image 112
developerwjk Avatar answered Oct 09 '22 07:10

developerwjk