0

its a spring boot project with tomcat 7 and java 6. i am trying to pre-compile jsps using jasper.Jspc but in generated java ELs are not being evaluated.

out.write(" script src=\"${pageContext.request.contextPath}/resources/js/AdvanceDeviceInfo.js\"> \r\n");

it should be something like :
out.write((java.lang.String)org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${pageContext.request.contextPath}"

if i use <%@ page isELIgnored="false" %>in individual jsps then its being evaluated properly. please help i don't to go and change every jsp.

Ant Script for precompilation

    <target name="main">
     <echo message="base dir: ${project.basedir}"/>
     <echo message="compile_classpath: ${compile_classpath}"/>
     <mkdir dir="${target_dir}/java"/>
     <mkdir dir="${target_dir}/resources"/>
     <path id="jspc_classpath">
        <path path="${compile_classpath}"/>
    </path>
     <!-- <property environment="org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING" value="false"/> -->
     <taskdef classname="org.apache.jasper.JspC" name="jasper" classpathref="jspc_classpath"/>
     <copy todir="${project.basedir}/target/jsp">
        <fileset dir="${project.basedir}/src/main/webapp">
            <include name="**/templates/*.jsp"/>
            <include name="**/views/**"/>
            <exclude name="**/CVS/**"/>
        </fileset>
     </copy>
    <copy todir="${project.build.outputDirectory}/public/resources">
        <fileset dir="${project.basedir}/src/main/webapp/resources">
            <include name="**/css/**"/>
            <include name="**/img/**"/>
            <include name="**/fonts/**"/>
            <include name="**/js/**"/>
            <include name="**/pie/**"/>
            <exclude name="**/CVS/**"/>
        </fileset>
     </copy>
     <jasper verbose="0"
        uriroot="${project.basedir}/target/jsp"
        webxml="${target_dir}/resources/jsp-web.xml"
        trimSpaces="true"
        outputDir="${target_dir}/java/" >
     </jasper>
    <copy todir="${project.build.outputDirectory}">
        <fileset dir="${target_dir}/resources"/>
    </copy>
    <javac srcdir="${target_dir}/java" 
        destdir="${project.build.outputDirectory}" 
        classpathref="jspc_classpath" 
        fork="true" 
        encoding="UTF-8"
        includeantruntime="false"/>
</target>
user2862544
  • 415
  • 3
  • 13

1 Answers1

1

There are a couple of solutions here.
The reason you see this is likely due to the version of your web.xml file. If the web.xml version is 2.3 then, by default, expressions will not be evaluated.

For example, you would might have this at the top of your web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
   <web-app id="WebApp_ID">

If so, you can modify it to a newer version (2.4, 2.5, 3.0) and expressions will be evaluated by default. For example, change the text above to this:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0">

and you should see your expressions start to be evaluated.

Alternatively, instead of changing the version of the web.xml file, you could add this JSP property group in the web.xml to set scripting-invalid to false.

   <jsp-property-group>
     <url-pattern>*.jsp</url-pattern>
     <scripting-invalid>false</scripting-invalid>
    </jsp-property-group>
user207421
  • 305,947
  • 44
  • 307
  • 483
JayS
  • 94
  • 5
  • 1
    Thanks, there is no Web. Xml in project so I can not do this. It's basically spring boot project. Is there any other way to do it – user2862544 Aug 16 '16 at 01:27
  • This was exactly my problem; many thanks. In my case my web.xml was set to 2.5, my JSP compiler only supported 2.4 (don't ask), so I actually had to downgrade to get the expressions evaluated. – gdt May 24 '18 at 11:20