刚写了一struts小练习中间遇到些问题在此总结一下,也希望能给看到此文的朋友些帮助:
----流氓天:376007394 于杭州 09.04.15 00:41
myeclipse里资源文件显示中文件问题
方法一:随便下载一个propedit_4.8.2_for_eclipse3.0 插件
在myeclipse 选择
help --sofware updates --find and Install
-- search for new features to install
—— new Local site 找到 propedit的目录
然后 默认下一步 就可以了
或者在find and install这步之后 search for new features to install --new remote site输入名称,网址http://propedit.sourceforge.jp/eclipse/updates/。->点击ok ->选中刚才新加的站点名称,点击finish->他会自动找出与你所用的eclipse版本相适应的插件全部选中->后面只要选择 install all即可
->最后会提示你重起你的eclipse
方法二:
在jdk的bin文件夹里有个专门转unicode的应用程序 native2ascii.exe
具体操作如下:
1、把你要转换的文字写到一个文件里,如c:/test.txt
2、在cmd方式中转到bin目录,如C:/j2sdk1.4.2_04/bin
3、输入命令 native2ascii c:/test.txt > c:/out.txt
4、将out.txt里对应的编码替代原文件的编码即可
当然也可以这样
native2ascii -encoding gb2312 ApplicationResources.properties ApplicationResources_zh.properties
多资源文件问题
struts-config.xml里用key来区别
<message-resources parameter="com.zh.struts.ApplicationResources" />
<message-resources parameter="com.zh.struts.ApplicationResources_zh_cn" key="zh" />
视图页面里用bundle来对应配置文件里的key
<bean:message key="username"/>/<bean:message bundle="zh" key="username"/>
<html:errors bundle="zh" property="password"/><html:errors property="name"/>
错误信息显示
ActionForm里面
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
ActionErrors errors=new ActionErrors();
if(getName().trim()==null||getName().length()<4){
errors.add("name",new ActionMessage("errors.name"));
}
if(getPassword().trim()==null||getPassword().length()<4){
errors.add("password", new ActionMessage("errors.password"));
}
return errors;
}
资源文件里
username=用户名
userpassword=密码
errors.name=用户名不能为空或太短
errors.password=密码不能为空或太短
视图页面里
<html:errors property="name"/>
取消按钮异常
刚在做一struts小练习碰到了一问题,就是当在login.jsp页面按提交按钮后,在login.do页面里再按取消的话则出现标签报org.apache.struts.action.InvalidCancelException错
网上搜了下解决方案如下:
试了下,嘿,没想还挺管用。
Any existing applications that use the Cancel processing will need to modify their struts-config.xml to set the cancellable property for actions which require it.
In Struts 1.2.9 the <set-property> is used to set the cancellable property for an action....
<action path="/fooAction" input="/foo.jsp" validate="true"> <set-property property="cancellable" value="true"/> <forward name="success" path="/bar.jsp"/> </action>
From Struts 1.3.x a new cancellable attribute can be used....
<action path="/fooAction" input="/foo.jsp" validate="true" cancellable="true"> <forward name="success" path="/bar.jsp"/> </action>
In both Struts 1.2.9 and Struts 1.3.x an exception handler can be configured to handle the InvalidCancelException
<action path="/fooAction" input="/foo.jsp" validate="true" cancellable="true"> <forward name="success" path="/bar.jsp"/> <exception key="errors.cancel" type="org.apache.struts.action.InvalidCancelException" path="/foo.jsp"/> </action>