【问题标题】:el is not being evaluated during precompilation of jsp with jspc of tomcat 7在使用tomcat 7的jspc预编译jsp期间未评估el
【发布时间】:2016-08-15 09:49:50
【问题描述】:

它是一个带有 tomcat 7 和 java 6 的 Spring Boot 项目。 我正在尝试使用 jasper.Jspc 预编译 jsps,但在生成的 java EL 中没有被评估。

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

应该是这样的:
out.write((java.lang.String)org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${pageContext.request.contextPath}"

如果我在单个 jsps 中使用 <%@ page isELIgnored="false" %>,那么它会被正确评估。请帮助我不要去改变每个jsp。

用于预编译的 Ant 脚本

    <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>

【问题讨论】:

  • 嗨,BalusC,你能帮帮我吗

标签: jsp tomcat ant el web.xml


【解决方案1】:

这里有几个解决方案。
您看到这种情况的原因可能是您的 web.xml 文件的版本。如果 web.xml 版本是 2.3,则默认情况下不会计算表达式。

例如,您可能会在 web.xml 文件的顶部包含以下内容:

<?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">

如果是这样,您可以将其修改为较新的版本(2.4、2.5、3.0),默认情况下将评估表达式。例如,将上面的文本更改为:

<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">

你应该会看到你的表达式开始被计算。

或者,您可以在 web.xml 中添加此 JSP 属性组以将 scripting-invalid 设置为 false,而不是更改 web.xml 文件的版本。

   <jsp-property-group>
     <url-pattern>*.jsp</url-pattern>
     <scripting-invalid>false</scripting-invalid>
    </jsp-property-group>

【讨论】:

  • 谢谢,没有网络。项目中的 XML 所以我不能这样做。它基本上是spring boot项目。有没有其他办法呢
  • 这正是我的问题;非常感谢。在我的例子中,我的 web.xml 设置为 2.5,我的 JSP 编译器只支持 2.4(不要问),所以我实际上必须降级才能评估表达式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-04
  • 1970-01-01
  • 1970-01-01
  • 2013-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多