Struts error message 的问题!
white-page.jsp
<%@page pageEncoding= "UTF-8 "%>
<%@page isELIgnored= "false "%>
<%@ taglib uri= "/WEB-INF/tlds/struts-bean.tld " prefix= "bean " %>
<bean:message key= "sso.onlinetest.result "/>
想要得到sso.onlinetest.result
但总是拿到null
if((name.length() < 4) || (name.length() > 20)){
message = new ActionMessage( "sso.onlinetest.result ", "错误:用户名必须在4-20位长度之间! ");
}
...
messages.add(ActionMessages.GLOBAL_MESSAGE, message);
return messages;
若用户名小于4个单词
我就将错误写在sso.onlinetest.result键里
以下是资源包
sso.label.username=Username:
sso.label.password=Password:
...
sso.onlinetest.result={0}
最后是外层的action
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
String username = request.getParameter( "username ");
String nickname = request.getParameter( "nickname ");
response.setHeader( "Charset ", "utf-8 ");
ActionMessages messages = null;
if(username != null){
username = new String(username.getBytes( "ISO8859-1 "), "UTF-8 ");
OnlineTestService testService = new UsernameOnlineTestService(username);
messages = testService.test();
}
else if(nickname != null){
nickname = new String(nickname.getBytes( "ISO8859-1 "), "UTF-8 ");
OnlineTestService testService = new UsernameOnlineTestService(username);
messages = testService.test();
}
this.saveMessages(request, messages);
return mapping.findForward( "white-page ");
}
不知道哪里有错!
------解决方法--------------------------------------------------------
<bean:message> 标记是用来输出资源(ApplicationResource.properties)文件里的内容的,key是资源文件的中键。你的资源文件如果没有用这个键的消息的话,当然是null了.