webwork转静态resultType

FreemarkerResult.class
public   class  FreemarkerResult  extends  WebWorkResultSupport
{

    
protected ActionInvocation invocation;

    
protected Configuration configuration;

    
protected ObjectWrapper wrapper;

    
protected String filename; // 要转换的静态页面名称

    
protected String template; // 静态页面模板的路径

    
protected String filepath; // 文件夹名

    
protected String location;

    
private String pContentType = "text/html";

                      
public void doExecute(String location, ActionInvocation invocation) throws IOException,
            TemplateException
    
{
        
this.location = location;
        
this.invocation = invocation;
        
this.configuration = getConfiguration();
        
this.wrapper = getObjectWrapper();

        
this.filename ="/"+ (String) conditionalParse(filename, invocation);

        
this.template = (String) conditionalParse(template, invocation);

        
this.filepath = ((String) conditionalParse(filepath, invocation))==null?"":((String) conditionalParse(filepath, invocation));

        
// 跳转页面的模板类
        Template template = configuration.getTemplate(location, deduceLocale());
        
// 转换静台页面的的模板类
        Template statictemplate = configuration.getTemplate(this.template, deduceLocale());
        TemplateModel model 
= createModel();
        String path 
= ServletActionContext.getServletContext().getRealPath(filepath)
                
+ File.separator;
        
this.delFile(path + filename);
        Writer out 
= new BufferedWriter(new OutputStreamWriter(
                
new FileOutputStream(path + filename)));

        
if (preTemplateProcess(template, model))
        
{
            
try
            
{
                
// 在指定路径生成静态页面
                statictemplate.process(model, out);
                
// 生成跳转的页面
                template.process(model, getWriter());

            }
 finally
            
{
                postTemplateProcess(template, model);
                postTemplateProcess(statictemplate, model);
            }

        }

    }



}

 

xwork.xml

 

< result - types >
    
< result - type name = " staticview "   class = " msocweb.common.FreemarkerResult " ></ result - type >
</ result - types >

< action name = " staticViewAction "   class = " msocweb.sitemanage_u.action.StaticViewAction " >
    
< external - ref name = " newsService " > newsService </ external - ref >
    
< result name = " success "  type = " staticview " >
        
< param name = " location " > websitemanage / success.ftl </ param >
        
< param name = " filename " > $ {filename} </ param >
        
< param name = " template " > index / newsdetail.ftl </ param >
        
< param name = " filepath " >/ static </ param >
    
</ result >                     
</ action >
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值