速度弹簧绑定
我需要将jsp存储在数据库中。我设法将 html 存储在数据库中并使用 escapeHTML 显示。我遇到的问题是 jsp 标签。他们始终没有解决。
我现在改用速度模板。我正忙于概念验证,并设法获得变量替换以及使用 Velocity.evaluate 工作的 if 语句。我现在在使用 spring 标签进行绑定时遇到问题,因为我无法解析宏。关于我的问题可能是什么的任何想法吗?
Velocity.init();
VelocityContext context = new VelocityContext();
String template="#springBind(\"command.firstname\") " +
" <input type=\"text\" size=\"50\" maxlength=\"255\" id=\"userName\" " +
" name=\"${status.expression}\" " +
" value=\"${status.value}\" " +
" <div class=\"requiredexample\"> " +
" e.g. [email protected] " +
" </div> " +
" <div class=\"errors\">${status.errorMessage}</div> ";
StringWriter writer = new StringWriter();
Velocity.evaluate(context, writer, "TemplateName", template);
System.out.println(writer);
I have a requirement to store a jsp in a database. I managed to store the html in the database and display using escapeHTML. The problem I had was with jsp tags. They never resolved.
I am now using Velocity Templates instead. I am busy with a proof of concept and managed to get variable substitution and the use of if statements working using Velocity.evaluate. I now have a problem using spring tags for binding as I cant get the macros to resolve. Any ideas on what my problem could be?
Velocity.init();
VelocityContext context = new VelocityContext();
String template="#springBind(\"command.firstname\") " +
" <input type=\"text\" size=\"50\" maxlength=\"255\" id=\"userName\" " +
" name=\"${status.expression}\" " +
" value=\"${status.value}\" " +
" <div class=\"requiredexample\"> " +
" e.g. [email protected] " +
" </div> " +
" <div class=\"errors\">${status.errorMessage}</div> ";
StringWriter writer = new StringWriter();
Velocity.evaluate(context, writer, "TemplateName", template);
System.out.println(writer);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了使用 Spring 标签,您需要以适当的方式配置 Velocity 引擎。它是由
速度配置器
。也许您可以按原样使用该类或检查其源代码以手动执行类似的配置。另外看看
VelocityViewResolver
和VelocityView
,它们可能包含对 Spring 标签很重要的东西。In order to use Spring tags you need to have a Velocity engine configured in appropriate way. It's done by
VelocityConfigurer
. Perhaps you can use that class as is or check its source to perform similar configuration manually.Also take a look at
VelocityViewResolver
andVelocityView
, they may contain something important for Spring tags.