Custom template engine for struts2

梦想与她 提交于 2019-12-11 09:23:56

问题


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:

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

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) 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
} 

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.



来源:https://stackoverflow.com/questions/4375653/custom-template-engine-for-struts2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!