从Struts 1.3更改为Struts 2.5后,速度显示美元符号

时间:2018-10-03 09:50:22

标签: java struts2 velocity

我卡在速度文件中,从Struts 1.3迁移到Struts 2.5,迁移到Struts 2.5之后,我无法从App层看到记录。它正在显示美元符号(您可以参考图像。我还将张贴我的速度代码并同时填充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

1 个答案:

答案 0 :(得分:0)

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