关于struts1转换器和插件

关于struts1转换器和插件

<controller processorClass="controller.CharacterController"></controller>
<message-resources parameter="MessageResources" />

<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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值