jsp - 在使用 tomcat 7 的 jspc 预编译 jsp 期间未评估 el

标签 jsp tomcat ant el web.xml

它是一个带有 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}"

如果我使用 <%@ page isELIgnored="false" %>然后在单个 jsps 中对其进行正确评估。请帮助我不要去更改每个 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>

最佳答案

这里有几个解决方案。
您看到这个的原因可能是由于您的 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>

关于jsp - 在使用 tomcat 7 的 jspc 预编译 jsp 期间未评估 el,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38952859/

相关文章:

java - 使用 ant/ivy 从 nexus 检索依赖项之间的 http 身份验证?

ant - 如何使 concat 任务因错误而失败?

ant - CruiseControl - PHP lint 检查通过 ANT 而不是通过 CruiseControl

java - 升级 Struts 2.3.16.2 库导致错误

tomcat - java.lang.ClassNotFoundException : org. apache.tomcat.jdbc.pool 数据源工厂

java - 在正在运行的 java 程序的后台执行 jsp 程序

java - 太阳能应该包含在网络应用程序中,还是单独

jsp - 如何解决struts2中的逗号分隔值

java - Web应用程序中的随机反馈

java - HTTPS 问题 - 在运行 Java 应用程序时,一些用户会收到 SEC7111