zoukankan      html  css  js  c++  java
  • struts1 plugin

    struts plugin 在struts.xml中注册之后,在系统启动之后调用 init 方法,通常在init方法中进行转化器的注册,在destory中移除转化器

    1. struts文件

    <plug-in className="com.test.util.DoubleConverterPlugIn"></plug-in>

    2.插件类实现

    public class DoubleConverterPlugIn implements PlugIn{

     public DoubleConverterPlugIn() {
     }

     public void destroy() {
            // 把注册移除
            ConvertUtils.deregister();  
     }

     public void init(ActionServlet arg0, ModuleConfig arg1)throws ServletException {
      ConvertUtils.register(new DoubleConverter(), Double.class);
     }
    }

    3. Double转化器的实现,此转化器在form bean中属性是double类型赋值时候自动调用

    public class DoubleConverter implements Converter{

     public Object convert(Class type, Object value) {
      Double doubleValue = new Double(0);
      if(value != null && !"".equals(value)){
       if(value instanceof String){
        String str = (String) value;
        str = str.replaceAll(",", "");
        try{
         doubleValue = new Double(str);
        }catch (Exception e) {
         e.printStackTrace()
        }
       }
      }
      return doubleValue;
     }
    }

  • 相关阅读:
    6.24Java网络编程之IP
    Network
    Network
    Network
    Network
    ES
    JavaWeb
    ES
    ES
    ES
  • 原文地址:https://www.cnblogs.com/rigid/p/3806414.html
Copyright © 2011-2022 走看看