struts2 的自定义模板引擎 [英] Custom template engine for struts2

查看:42
本文介绍了struts2 的自定义模板引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个自定义的模板引擎,例如 velocityfreemarker,它们将在基于 struts 2 的应用程序中使用.为什么我不想使用任何可用的模板引擎是因为,我想保持 HMTL 固定且可被 Dreamweaver 编辑意味着没有 struts 标签或 JSTL.这些值将被注入 Xpath 或现有 HTML 标签值的简单字符串替换.我需要:

I want to create a custom template engine like velocity or freemarker which will be used in struts 2 based application. Why I don't want to use any of the available template engines is because, I want to keep the HMTL fixed and editable by dreamweaver means no struts tags or JSTL. The values will be injected with Xpath or simple string replacement of values of existing HTML tags. I require:

纯 HTML + 一些配置(属性/xml)+ 数据 =>

plain HTML + some configuration (properties/xml) + data =>

用数据填充的 HTML + 一些动态生成的 javascripts

HTML populated with data + some dynamically generated javascripts

推荐答案

1) 定义一个包,其中包含结果类型的名称以及当操作返回该结果类型时将调用的类.

1) Define a package with the name of your result type and the class that will be called when an action returns that result type.

<package name="default" namespace="/" extends="struts-default">
  <result-types>
    <result-type name="myResultType" class="com.awesome.MyResult"/> 
  </result-types>
  .... actions and other things...
</package>

2) 实现 Struts 2 结果类型类:

2) Implement the Struts 2 result type class:

package com.awesome;
public class MyResult extends StrutsResultSupport{
  //1) read the the target file
  //2) process/transform the target file
  //3) write out the transformed file as the result
} 

在 Dave Newton 的Apache Struts 2 Web 应用程序开发"中对此有很好的描述.我知道上面的类没有实现,但我敢打赌你可以从这里找到你需要的东西.

There is a good description of this in "Apache Struts 2 web application Development" by Dave Newton. I know the above class isn't implemented but I bet you can find what you need from here.

这篇关于struts2 的自定义模板引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆