msg = getText("error.email.exist"); //此行报错
return "input";java.lang.NullPointerException
at com.opensymphony.xwork2.util.LocalizedTextUtil.createMissesKey(LocalizedTextUtil.java:240)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findResourceBundle(LocalizedTextUtil.java:219)
at com.opensymphony.xwork2.util.LocalizedTextUtil.getMessage(LocalizedTextUtil.java:604)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findMessage(LocalizedTextUtil.java:645)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:360)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:293)
at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:173)
at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:88)
at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:71)
at com.eu3c.struts.account.LoginAction.execute(LoginAction.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)……
return "input";java.lang.NullPointerException
at com.opensymphony.xwork2.util.LocalizedTextUtil.createMissesKey(LocalizedTextUtil.java:240)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findResourceBundle(LocalizedTextUtil.java:219)
at com.opensymphony.xwork2.util.LocalizedTextUtil.getMessage(LocalizedTextUtil.java:604)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findMessage(LocalizedTextUtil.java:645)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:360)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:293)
at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:173)
at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:88)
at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:71)
at com.eu3c.struts.account.LoginAction.execute(LoginAction.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)……
getText重名了吧。 或者说你没有定义text 的get set 方法吧。不行的话 你把你的
代码 粘出来 瞅瞅。
这是要去资源文件里面的东西啊
上面的情况结果 msg = "error.mail.exist"错误的原因不在这里:
1:
你的资源文件: 2: 有没设置好 在strust.xml里面配的 如 <constant name="struts.custom.i18n.resources" value="message" />
还有可能是消息配置文件路径不对。
还有可能是消息配置文件文件名不对。你是带Locale的。应该在文件名最后加zh_cn等。
看看你文件内部有没有用全角的=等等。
问一下 你是带Locale的 这一句什么意思
多语言版本Struts默认通过request的也就是浏览器发送的语言字符串来辨认你messageResource的文件名的最后几位是否相同。
查看浏览器Locale的方法:
1)手动法
IE的话,internet选项中外观->语言。2)Javascript查看法<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript"> alert(navigator.userLanguage || navigator.language);
</script></head>
<body></body>
</html>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<constant name="struts.objectFactory" value="spring"></constant>
<constant name="struts.custom.il8n.resources" value="com.test.struts.ApplicationResources"></constant>
<constant name="struts.il8n.encoding" value="UTF-8"></constant>
<constant name="struts.il8n.reload" value="true"></constant>
资源文件在com.test.struts包里 文件名都以ApplicationResources开头
ApplicationResources_en.properties
ApplicationResources_ja.properties
ApplicationResources_zh.properties
ApplicationResources.properties
这样设置有问题吗?
直接放在src下。
2.在action中直接调用:
addFieldError("属性", this.getText("资源文件中的key",new String[]{"参数"}));
没有参数的话直接写key。别的就没有什么了。
com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:359)
org.apache.struts2.dispatcher.Dispatcher.cleanUpRequest(Dispatcher.java:751)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:437)高手们指点下