从 struts 1.3 更改为 struts 2.5 后显示美元符号的速度

Velocity showing dollar sign after changing from struts 1.3 to struts 2.5

我卡在 velocity 文件中,从 struts 1.3 迁移到 struts 2.5,迁移到 struts 2.5 后,我无法从 App 层看到记录。它显示美元符号(你可以参考图片。我会 post 我的速度代码和 sturts 2.5 文件。我需要帮助。

速度文件:

<tr>
        <td class="distable" colspan="3">
            <table border='0' width=100% align=center cellspacing="1" cellpading="1" class="thetable">
                <tr>
                    <td class="distitle" width=30%>User Name</td>
                    <td class="distitle" width=15%><=2</td>
                    <td class="distitle" width=15%>>2</td>
                    <td class="distitle" width=15%>Total</td>
                    <td class="distitle" width=10%>TAT(%)</td>
                </tr>
                       #set($totalEarly = 0)
                       #set($totalLate = 0)
                       #if(!$list.isEmpty($request.getAttribute('finalRes')))
                            #foreach( $res in $request.getAttribute('finalRes') )
                                #set($totalEarly = $totalEarly+$res.EARLY)
                                #set($totalLate = $totalLate+$res.LATE)
                            #end
                       #foreach( $res in $request.getAttribute('finalRes') )
                                                    #set ($index = $loopIndex + 1)
            #set ($color = "tbltxt1" )
            #if (($index % 2) > 0 )
            #set ($color = "tbltxt2")   
            #end    
                      <tr>
                        <td class='$color'><div style="padding-left:10px">$!{res.SNAME}</div></td>
                        <td class='$color'>$!{res.EARLY}</td>
                ##      <td class='$color'><a id="lnkDataEntryReportDetails"  onClick="window.open('$request.contextPath/detail.do?q=det&type=de&month=$params.month&year=$params.year&brchCode=$params.brchCode&uid=$res.USERID')">$!{res.LATE}</a></td>
                         <td class='$color'><a href="#"  onClick="window.open('$request.contextPath/detail.do?q=det&type=de&month=$params.month&year=$params.year&brchCode=$params.brchCode&uid=$res.USERID'); return false">$!{res.LATE}</a></td>
                        <td class='$color'>$math.add($res.EARLY,$res.LATE)</td>
                        <td class='$color'>$math.roundTo(2,$math.mul($math.div($res.EARLY,$math.add($res.EARLY,$res.LATE)),100)) </td>
                      </tr>
                       #end
                        <tr>
                        <td class="tbltxt2 total"><div style="padding-left:10px">Grand Total</div></td>
                        <td class="tbltxt2 total">$!{totalEarly}</td>
                        <td class="tbltxt2 total">$!{totalLate}</td>
                        <td class="tbltxt2 total">$math.add($totalEarly,$totalLate)</td>
                        <td class="tbltxt2 total">$math.roundTo(2,$math.mul($math.div($totalEarly,$math.add($totalEarly,$totalLate)),100)) </td>
                      </tr>
                      #else
                        <tr>
                          <td colspan="13" class="tbltxt2">No Results Returned</td>
                        </tr>
                      #end
            </table>
        </td>
    </tr>

Struts 2.5.xml 文件:

<action name="dePerfReport" class="com.ifc.am.web.workflow.ReportAction"
        method="dePerf">
        <interceptor-ref name="basicStack" />
        <result name="success" type="velocity">/views/uw/uw.rep.dePerf.vm</result>
    </action>

Java方法:

public String ReportExample() throws Exception{

    Muser user =    (Muser) getServletRequest().getSession().getAttribute("muser");
    long userid = 0;
    if(user!=null){
         userid = user.getLseqid(); 
    }


    String month = request.getParameter("year") == null ?  "" : request.getParameter("month").trim() ;
    String year = request.getParameter("month") == null ?  "" : request.getParameter("year").trim() ;
    String brchCode = request.getParameter("brchCode") == null ?  "" : request.getParameter("brchCode").trim() ;
    List brch = new DaoUtil().getBrch();

    //log.debug(month+"-->"+year+"brchCode:"+brchCode);

    List result = new ArrayList(); 
    if(month.length() > 0 && year.length() > 0 && brchCode.length() > 0)
    {
        Session session = HibernateUtil.getSessionInstance();               
        try {
            result = session.createSQLQuery(SQL.RPT_DE_PERFORMANCE)
            .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
            .setParameter("MONTH", month)
            .setParameter("YEAR", year)
            .setParameter("BRANCH", brchCode)
            //.setParameter("USERID", userid)
            .list();

        } catch (HibernateException e) {
            log.fatal(e.getClass()+"[ "+e.getMessage()+" ]");
            HibernateUtil.closeSessionInstanceWithOutFlush(session);
        }catch (Exception e1) {
            log.fatal(e1.getClass()+"[ "+e1.getMessage()+" ]");
            HibernateUtil.closeSessionInstanceWithOutFlush(session);
        }
        finally {
            HibernateUtil.closeSessionInstance(session);
        }
    }

    request.setAttribute("year", year);
    request.setAttribute("month", month);
    request.setAttribute("brchCode", brchCode);
    request.setAttribute("finalRes", result);
    request.setAttribute("brch", new DaoUtil().getBrch());

    return SUCCESS;     

}

This image is output from velocity file

要解决此问题,请使用 velocity 1.7 和 velocity-tools 1.4。 Struts 2.5 不支持更高版本的速度。请在您的 eclipse 中检查您的 jar 文件。在某些情况下,相同的 jar 将在您的项目中重复。