首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

关于struts1转换器跟插件

2012-09-03 
关于struts1转换器和插件关于struts1转换器和插件 controller processor/plug-in classNameplugin.Da

关于struts1转换器和插件
关于struts1转换器和插件

<controller processor/>
   
<plug-in className="plugin.DateConvertPlugIn"></plug-in>


转换器:
1,关于控制器的配置必须写在<message-resources>的后面,否则会报错!
2,
public class CharacterController extends RequestProcessor {
@Override
protected boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub

System.out.println("struts 控制器已经加入");

try {
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return super.processPreprocess(request, response);
}
}



插件:
1,
public class UtilDateConvter implements Converter {

public Object convert(Class arg0, Object text) {
// TODO Auto-generated method stub
Date date=null;

if(text==null)
return (null);
if(text instanceof Date)
return text;
if(text instanceof String)
{

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
try {
date= sdf.parse((String)text);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return date;
}

}
2,
public class DateConvertPlugIn implements PlugIn {

public void destroy() {
// TODO Auto-generated method stub

}

public void init(ActionServlet servlet, ModuleConfig config)
throws ServletException {
System.out.println("日期转换器开始工作。。。");
ConvertUtils.register(new UtilDateConvter(), java.util.Date.class);

}

}

国际化:
<body>
  <html:errors/>
    <form action="users.do" method="post" name="myform">
    用户ID:<input type="text" name="users.uid"/><br/>
    <bean:message key="login.uname"/><input type="text" name="users.uname"/><br/>
    <bean:message key="login.upass"/><input type="text" name="users.upass"/><html:errors property="password_error"/><br/>
    登录时间:<input type="text" name="users.loginTime" /><br/>
    <input type="hidden" name="method" value="dologin"/>
    <input type="submit" value='<bean:message key="login.submit"/>'/>
    </form>
  </body>

热点排行