gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:51:24 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com