【问题标题】:Velocity showing dollar sign after changing from struts 1.3 to struts 2.5从 struts 1.3 更改为 struts 2.5 后显示美元符号的速度
【发布时间】:2018-10-03 09:50:22
【问题描述】:

我卡在速度文件中,从 struts 1.3 迁移到 struts 2.5,迁移到 struts 2.5 后,我无法从 App 层看到记录。它显示美元符号(您可以参考图片。我将发布我的速度代码和 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

【问题讨论】:

  • 你如何构建你的项目?行家?你包括 MathTool 吗?见stackoverflow.com/questions/7415805/…
  • 是的,我使用 maven 构建我的项目。我确实在 Toolbox.xml 中包含了 MathTool
  • mathapplicationorg.apache.velocity.tools.generic.MathTool
  • 还“将 MathTool 放入您的上下文中:context.put("math", new MathTool()) 或使用 VelocityTools 上下文支持在您使用它们时自动提供工具。”
  • 你的意思是 context.xml 文件?顺便说一句,我已经在 pom.xml 中添加了依赖项

标签: java struts2 velocity


【解决方案1】:

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

【讨论】:

  • 实际上,jar 文件在 struts 2.5 中存在问题。我推荐使用spring框架
猜你喜欢
  • 1970-01-01
  • 2018-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-04
相关资源
最近更新 更多