速度文件中未处理 HTML 标签

发布于 2024-12-13 01:38:47 字数 6070 浏览 2 评论 0原文

我有一个使用速度的弹簧应用程序。有一个石英调度程序每隔几分钟运行一次并发送电子邮件。电子邮件的内容是根据速度模板生成的。问题是,如果该应用程序使用 maven 的 tomcat 插件运行,则电子邮件模板文件中的 HTML 标记将得到正确处理。但是,如果我将该应用程序放在独立的 tomcat 安装中并从那里运行它,标签将在电子邮件中显示为

<p> <br /> 

,并且不会设置动态内容。我无法弄清楚确切的问题是什么。我的应用程序中的某些 jar 是否与 tomcat 实例冲突?以下是其 lib 文件夹中的 jar 列表:

activation-1.1.jar                             juli-6.0.32.jar
activemq-all-5.4.2.jar                         junit-4.8.1.jar
annogen-0.1.0.jar                              log4j-1.2.16.jar
ant-1.7.0.jar                                  lucene-analyzers-3.1.0.jar
ant-launcher-1.7.0.jar                         lucene-core-3.1.0.jar
antlr-2.7.6.jar                                lucene-highlighter-3.1.0.jar
ant-nodeps-1.7.0.jar                           lucene-memory-3.1.0.jar
aopalliance-1.0.jar                            lucene-misc-3.1.0.jar
asm-3.1.jar                                    lucene-smartcn-3.1.0.jar
aspectjrt-1.6.9.jar                            lucene-spatial-3.1.0.jar
aspectjweaver-1.6.8.jar                        lucene-spellchecker-3.1.0.jar
axiom-api-1.2.7.jar                            lucene-stempel-3.1.0.jar
axiom-dom-1.2.5.jar                            mail-1.4.jar
axiom-impl-1.2.7.jar                           mysql-connector-java-5.1.13.jar
axis2-1.4.jar                                  neethi-3.0.0.jar
axis2-adb-1.3.jar                              opencsv-2.1.jar
axis2-adb-codegen-1.3.jar                      opensaml-1.1.jar
axis2-codegen-1.3.jar                          oro-2.0.8.jar
axis2-kernel-1.3.jar                           quartz-1.6.1.jar
axis2-mtompolicy-1.3.jar                       rampart-core-1.3.jar
axis2-xmlbeans-1.3.jar                         rampart-policy-1.3.jar
axis-wsdl4j-1.5.1.jar                          rampart-trust-1.3.jar
backport-util-concurrent-3.1.jar               slf4j-api-1.5.8.jar
cas-client-core-3.1.10.jar                     slf4j-log4j12-1.5.2.jar
cglib-2.2.jar                                  solr-analysis-extras-3.1.0.jar
commons-beanutils-1.7.0.jar                    solr-commons-csv-3.1.0.jar
commons-codec-1.4.jar                          solr-core-3.1.0.jar
commons-collections-3.2.1.jar                  solr-solrj-3.1.0.jar
commons-dbcp-1.2.2.jar                         spring-aop-3.0.3.RELEASE.jar
commons-digester-1.7.jar                       spring-asm-3.0.5.RELEASE.jar
commons-discovery-0.2.jar                      spring-aspects-3.0.5.RELEASE.jar
commons-fileupload-1.2.2.jar                   spring-beans-3.0.5.RELEASE.jar
commons-httpclient-3.1.jar                     spring-context-3.0.5.RELEASE.jar
commons-io-2.0.jar                             spring-context-support-3.0.5.RELEASE.jar
commons-lang-2.5.jar                           spring-core-3.0.5.RELEASE.jar
commons-logging-1.1.1.jar                      spring-expression-3.0.5.RELEASE.jar
commons-pool-1.3.jar                           spring-jdbc-3.0.5.RELEASE.jar
commons-validator-1.3.0.jar                    spring-jms-3.0.5.RELEASE.jar
dom4j-1.6.1.jar                                spring-modules-validation-0.8.jar
ehcache-core-2.2.0.jar                         spring-orm-3.0.5.RELEASE.jar
geronimo-activation_1.1_spec-1.0.1.jar         spring-oxm-3.0.5.RELEASE.jar
geronimo-javamail_1.4_spec-1.2.jar             spring-security-cas-client-    3.0.3.RELEASE.jar
geronimo-jms_1.1_spec-1.1.jar                  spring-security-core-3.0.3.RELEASE.jar
geronimo-jta_1.0.1B_spec-1.1.1.jar             spring-security-web-3.0.3.RELEASE.jar
geronimo-stax-api_1.0_spec-1.0.1.jar           spring-tx-3.0.3.RELEASE.jar
hibernate-annotations-3.5.4-Final.jar          spring-web-3.0.5.RELEASE.jar
hibernate-commons-annotations-3.2.0.Final.jar  spring-webmvc-3.0.5.RELEASE.jar
hibernate-core-3.5.4-Final.jar                 spring-ws-core-2.0.2.RELEASE.jar
hibernate-entitymanager-3.5.4-Final.jar        spring-xml-2.0.2.RELEASE.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar          stax2-api-3.0.2.jar
hibernate-search-3.4.1.Final.jar               stax-api-1.0.1.jar
hibernate-search-analyzers-3.4.1.Final.jar     stax-api-1.0-2.jar
hibernate-validator-4.1.0.Final.jar            
httpcore-4.0-alpha5.jar                        
httpcore-nio-4.0-alpha5.jar                    tribes-6.0.32.jar
httpcore-niossl-4.0-alpha5.jar                 validation-api-1.0.0.GA.jar
icu4j-2.6.1.jar                                velocity-1.6.4.jar
itextpdf-5.1.1.jar                             velocity-tools-1.4.jar
jackson-core-asl-1.5.3.jar                     woden-api-1.0M9.jar
jackson-mapper-asl-1.5.3.jar                   woodstox-core-asl-4.0.8.jar
jasypt-1.8.jar                                 wsdl4j-1.6.1.jar
javassist-3.9.0.GA.jar                         ws-humanresources-13.0.1.jar
jaxen-1.1.jar                                  wss4j-1.5.3.jar
jdom-1.0.jar                                   wstx-asl-3.2.4.jar
jetty-continuation-8.0.0.M3.jar                xalan-2.7.0.jar
jetty-http-8.0.0.M3.jar                        xbean-2.1.0.jar
jetty-io-8.0.0.M3.jar                          xbean-spring-3.6.jar
jetty-server-8.0.0.M3.jar                      xercesImpl-2.8.1.jar
jetty-util-8.0.0.M3.jar                        xml-apis-1.3.03.jar
joda-time-1.6.jar                              xmlParserAPIs-2.6.2.jar
js-1.6R2.jar                                   XmlSchema-1.3.2.jar
jstl-1.2.jar                                   xmlsec-1.4.0.jar
jta-1.1.jar                                    xom-1.0.jar

速度模板的内容是:

#if( ${user.middleName} )
#set( $fullName = "${user.firstName} ${user.middleName} ${user.lastName}" )
#else
#set( $fullName = "${user.firstName} ${user.lastName}" )
#end
#set( $subject = "User name for ${fullName} is changed" ) 
#set( $from = "[email protected]" )
#set( $to = "${user.email}" )

<p>Hi ${fullName}</p>

<p>Thanks!<br></p>

感谢任何帮助,因为我已经无能为力了。

I have a spring app which uses velocity. There is a quartz scheduler that runs every few minutes and sends out emails. The email's content is generated from a velocity template. The problem is that if that app is run using the maven's tomcat plugin, then the HTML tags in the email template file are processed correctly. But if I put that app in a standalone tomcat installation and run it from there, the tags show up in the email as

<p> <br /> 

, and no dynamic content is set. I can't figure out what the exact problem is. Is some jar in my app conflicting with the tomcat instance? Here's a list of the jars in its lib folder :

activation-1.1.jar                             juli-6.0.32.jar
activemq-all-5.4.2.jar                         junit-4.8.1.jar
annogen-0.1.0.jar                              log4j-1.2.16.jar
ant-1.7.0.jar                                  lucene-analyzers-3.1.0.jar
ant-launcher-1.7.0.jar                         lucene-core-3.1.0.jar
antlr-2.7.6.jar                                lucene-highlighter-3.1.0.jar
ant-nodeps-1.7.0.jar                           lucene-memory-3.1.0.jar
aopalliance-1.0.jar                            lucene-misc-3.1.0.jar
asm-3.1.jar                                    lucene-smartcn-3.1.0.jar
aspectjrt-1.6.9.jar                            lucene-spatial-3.1.0.jar
aspectjweaver-1.6.8.jar                        lucene-spellchecker-3.1.0.jar
axiom-api-1.2.7.jar                            lucene-stempel-3.1.0.jar
axiom-dom-1.2.5.jar                            mail-1.4.jar
axiom-impl-1.2.7.jar                           mysql-connector-java-5.1.13.jar
axis2-1.4.jar                                  neethi-3.0.0.jar
axis2-adb-1.3.jar                              opencsv-2.1.jar
axis2-adb-codegen-1.3.jar                      opensaml-1.1.jar
axis2-codegen-1.3.jar                          oro-2.0.8.jar
axis2-kernel-1.3.jar                           quartz-1.6.1.jar
axis2-mtompolicy-1.3.jar                       rampart-core-1.3.jar
axis2-xmlbeans-1.3.jar                         rampart-policy-1.3.jar
axis-wsdl4j-1.5.1.jar                          rampart-trust-1.3.jar
backport-util-concurrent-3.1.jar               slf4j-api-1.5.8.jar
cas-client-core-3.1.10.jar                     slf4j-log4j12-1.5.2.jar
cglib-2.2.jar                                  solr-analysis-extras-3.1.0.jar
commons-beanutils-1.7.0.jar                    solr-commons-csv-3.1.0.jar
commons-codec-1.4.jar                          solr-core-3.1.0.jar
commons-collections-3.2.1.jar                  solr-solrj-3.1.0.jar
commons-dbcp-1.2.2.jar                         spring-aop-3.0.3.RELEASE.jar
commons-digester-1.7.jar                       spring-asm-3.0.5.RELEASE.jar
commons-discovery-0.2.jar                      spring-aspects-3.0.5.RELEASE.jar
commons-fileupload-1.2.2.jar                   spring-beans-3.0.5.RELEASE.jar
commons-httpclient-3.1.jar                     spring-context-3.0.5.RELEASE.jar
commons-io-2.0.jar                             spring-context-support-3.0.5.RELEASE.jar
commons-lang-2.5.jar                           spring-core-3.0.5.RELEASE.jar
commons-logging-1.1.1.jar                      spring-expression-3.0.5.RELEASE.jar
commons-pool-1.3.jar                           spring-jdbc-3.0.5.RELEASE.jar
commons-validator-1.3.0.jar                    spring-jms-3.0.5.RELEASE.jar
dom4j-1.6.1.jar                                spring-modules-validation-0.8.jar
ehcache-core-2.2.0.jar                         spring-orm-3.0.5.RELEASE.jar
geronimo-activation_1.1_spec-1.0.1.jar         spring-oxm-3.0.5.RELEASE.jar
geronimo-javamail_1.4_spec-1.2.jar             spring-security-cas-client-    3.0.3.RELEASE.jar
geronimo-jms_1.1_spec-1.1.jar                  spring-security-core-3.0.3.RELEASE.jar
geronimo-jta_1.0.1B_spec-1.1.1.jar             spring-security-web-3.0.3.RELEASE.jar
geronimo-stax-api_1.0_spec-1.0.1.jar           spring-tx-3.0.3.RELEASE.jar
hibernate-annotations-3.5.4-Final.jar          spring-web-3.0.5.RELEASE.jar
hibernate-commons-annotations-3.2.0.Final.jar  spring-webmvc-3.0.5.RELEASE.jar
hibernate-core-3.5.4-Final.jar                 spring-ws-core-2.0.2.RELEASE.jar
hibernate-entitymanager-3.5.4-Final.jar        spring-xml-2.0.2.RELEASE.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar          stax2-api-3.0.2.jar
hibernate-search-3.4.1.Final.jar               stax-api-1.0.1.jar
hibernate-search-analyzers-3.4.1.Final.jar     stax-api-1.0-2.jar
hibernate-validator-4.1.0.Final.jar            
httpcore-4.0-alpha5.jar                        
httpcore-nio-4.0-alpha5.jar                    tribes-6.0.32.jar
httpcore-niossl-4.0-alpha5.jar                 validation-api-1.0.0.GA.jar
icu4j-2.6.1.jar                                velocity-1.6.4.jar
itextpdf-5.1.1.jar                             velocity-tools-1.4.jar
jackson-core-asl-1.5.3.jar                     woden-api-1.0M9.jar
jackson-mapper-asl-1.5.3.jar                   woodstox-core-asl-4.0.8.jar
jasypt-1.8.jar                                 wsdl4j-1.6.1.jar
javassist-3.9.0.GA.jar                         ws-humanresources-13.0.1.jar
jaxen-1.1.jar                                  wss4j-1.5.3.jar
jdom-1.0.jar                                   wstx-asl-3.2.4.jar
jetty-continuation-8.0.0.M3.jar                xalan-2.7.0.jar
jetty-http-8.0.0.M3.jar                        xbean-2.1.0.jar
jetty-io-8.0.0.M3.jar                          xbean-spring-3.6.jar
jetty-server-8.0.0.M3.jar                      xercesImpl-2.8.1.jar
jetty-util-8.0.0.M3.jar                        xml-apis-1.3.03.jar
joda-time-1.6.jar                              xmlParserAPIs-2.6.2.jar
js-1.6R2.jar                                   XmlSchema-1.3.2.jar
jstl-1.2.jar                                   xmlsec-1.4.0.jar
jta-1.1.jar                                    xom-1.0.jar

The content of the velocity template is :

#if( ${user.middleName} )
#set( $fullName = "${user.firstName} ${user.middleName} ${user.lastName}" )
#else
#set( $fullName = "${user.firstName} ${user.lastName}" )
#end
#set( $subject = "User name for ${fullName} is changed" ) 
#set( $from = "[email protected]" )
#set( $to = "${user.email}" )

<p>Hi ${fullName}</p>

<p>Thanks!<br></p>

Any help is appreciated because I am at my wit's end.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

守不住的情 2024-12-20 01:38:47

听起来字符正在被转义...最好查看 html 源代码,但很可能您会看到 <和>而不是 <和>。如果您将 html 传递到速度上下文中的速度模板中,通常会发生这种情况(取决于配置)。不过,您的情况不应该如此,因为您的 html 代码已经在模板中,但它在某个地方被转义了。

我认为转义是在速度处理模板之后发生的。您应该看看您的 tomcat 配置以及处理模板后您对电子邮件所做的事情

抱歉,我无法提供更多帮助,但您的问题没有太多内容

It sounds like the characters are being escaped... best to look at the html source but it's likely you'll see < and > instead of < and >. This would typically happen (depending on config) if you passed html into a velocity template in the velocity context. This shouldn't be the case for you though, as your html code is already in the template but it is being escaped somewhere.

I think the escaping is happening after velocity has processed the template. You should take a look at your tomcat config and also what you're doing with the email after processing the template

Sorry I can't be of more help but there isn't a lot to go on in your question

绝不服输 2024-12-20 01:38:47

电子邮件是否以文本/纯文本而不是文本/html 形式发送。检查mime类型是否正确

Is the email is being sent as text/plain instead of text/html. Check out the mime type and see if it's correct

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文