public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
ActionErrors actionErrors=new ActionErrors();
if(userName==null || userName.equals(""))
{
actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("用户名不能为空!"));
}
else if(userName.length()>15)
{
actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("你输入的用户名长度超出系统限制!"));
}
if(userPassword==null || userPassword.equals(""))
{
actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("密码不能 为空!"));
}
else if(userPassword.length()>15)
{
actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("密码长度超长!"));
}
return actionErrors;
}
在struts-config.xml中加上:validate=“true”;为什么验证还是无效啊???各位前辈帮帮忙……
HttpServletRequest request) {
// TODO Auto-generated method stub
ActionErrors actionErrors=new ActionErrors();
if(userName==null || userName.equals(""))
{
actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("用户名不能为空!"));
}
else if(userName.length()>15)
{
actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("你输入的用户名长度超出系统限制!"));
}
if(userPassword==null || userPassword.equals(""))
{
actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("密码不能 为空!"));
}
else if(userPassword.length()>15)
{
actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("密码长度超长!"));
}
return actionErrors;
}
在struts-config.xml中加上:validate=“true”;为什么验证还是无效啊???各位前辈帮帮忙……
解决方案 »
- PreparedStatement ps = conn.prepareStatement(sql);空指针,求解啊!
- 急!! 一个求和的问题。谢谢各位!!!!!!!
- jsp不认识我
- !!!!!!!!!!!!急救——javaScript验证问题
- 哭求解决方案!关于聊天室的列表更新的问题(再不解决就死了)
- 急!!!!stuts 页面提交后 转到另一个页面 页面bean没有重新载入,无法显示正确结果
- jdbc驱动按装完后应该怎么样把他们加入到classpath?说的越细越好(急急)在线等待!!!
- 急急急高手请给代码谢谢,(用JSP做有关web页面接收附件之类的程序)
- 请教一个JSP连接MYSQL的问题
- 谁帮我搞定这个文件,50分送他/她
- Servlet action is not available问题
- tagsupport是否会做session清空的操作doEndTag()为什么时获取不session的内容
你先尝试在validate方法里面设置断电或者打印下参数。看代码是否执行到这了。
对于你这个问题,在Struts-config.xml的action中配置了validate=true,还要配置input,作为错误输出页面
<action
attribute="logInForm"
input="/LogIn.jsp"
name="logInForm"
path="/login"
scope="request"
type="LogInAction"
validate="true" >
<forward name="success" path="/success.jsp" />
<forward name="fail" path="/fail.jsp" />
</action>
我已经有一个input了啊,这是登陆界面!再加一个就会提示错误了!
C:\JDK1.6\jdk1.6.0_03\bin\native2ascii.exe
输入你的中文,回车,把转码复制到properties中,然后定义一个名字,这个名子在ActionMessage中就直接用就可以,注意修改properties要重启服务
比如,ApplicationResources.properties中内容如下# Resources for parameter 'com.knight.struts.ApplicationResources'
# Project Test
login.needpwd=\u8bf7\u8f93\u5165\u5bc6\u7801
在Form中
new ActionMessage("login.needpwd")就可以了
HttpServletRequest request) {
ActionErrors errors = super.validate(mapping, request);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
if (errors.size("startDate") == 0 && errors.size("endDate") == 0) {
Date start = format.parse(startDate);
Date end = format.parse(endDate);
if (end.compareTo(start) <= 0) {
ActionMessage msg = new ActionMessage("errors.startAndEnd");
errors.add("startAndEnd", msg);
}
}
} catch (ParseException e) {
}
return errors;
}errors.startAndEnd在ApplicationResources.properties中定义
errors.startAndEnd \u7ED3\u675F\u65E5\u671F\u5FC5\u987B\u5927\u4E8E\u5F00\u59CB\u65E5\u671F页面上
<span style="color: red">
<html:errors property="startAndEnd" />
</span>