朋友们,请教一个问题,用struts2.0做国际化,要是我要国际化的数据是从数据库里取出来的怎么国际化呀,现在假如我要从表里取出一列的数据来,而那列的数据是中文的,现在查询出来后怎么做国际化处理呢?注意,以后可能会向这个表里的再添加数据。

解决方案 »

  1.   

    谢谢关注!此问题自己已解决。答案:
    data = sb.getAllInfo();
    Iterator it=data.iterator();
    Spending sp=null;
    ActionContext ctx=ActionContext.getContext();
    while(it.hasNext()){
    sp=(Spending) it.next();
    //先遍历集合,把字段列中为中文的值取出给action的属性
    payment_cn=sp.getPayments_CN();
    payment_en=sp.getPayments_EN();
    feeType_cn=sp.getFeeType_Cn();
    feeType_en=sp.getFeeType_En();
    suppliers_cn=sp.getCont_CompName_CN();
    suppliers_en=sp.getCont_CompName_EN();
    /*
    用getText()方法取得资源文件里的值,注意在资源文件中用表达式作为占位符,
    例在中文资源文件中:ZhiFuFangShi=${payment_cn},在英文资源文件中:ZhiFuFangShi=${payment_en}
    */
    ctx.put("payment",getText("ZhiFuFangShi"));
    ctx.put("feeType",getText("FeiYongLeiXing"));
    ctx.put("supplier",getText("GongYingShang"));
    //通过标识取得值
    String payment=(String)ctx.get("payment");
    String feeType=(String)ctx.get("feeType");
    String supplier=(String)ctx.get("supplier");
    //重新封装这几列的值
    sp.setPayment(payment);
    sp.setFeeTypes(feeType);
    sp.setSuppliers(supplier);
    //重新装到另外一个集合
    allInfo.add(sp);
    }
      

  2.   

    另外还想讨论一下,做中英系统时,java中的国际化完全可以满足要求(我认为是的),为什么还要用以前的老办法,在页面上用单选按钮组来做中英文转化呢?