在eclipse+myEclipse下开发的struts1.2.6应用
输入合法是返回我要的结果
但是validation失败时出错
jsp中用<html:errors/>输出
Form中validate函数如下:
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if ((userName == null) || (userName.length() < 1))
errors.add("username",new ActionMessage(hello.no.username.error"));
return errors;
}
Action中的business validation部分代码如下:
ActionMessages errors = new ActionMessages();
String userName = helloForm.getUserName();
String badUserName = "badguy";
if (userName.equalsIgnoreCase(badUserName)) {
errors.add("username", new ActionMessage("hello.dont.talk.to.badguy",
badUserName));
saveMessages(request, errors);
return (new ActionForward(mapping.getInput()));
}
表单为空时,错误信息如下:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: org.apache.struts.action.ActionMessage
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
新手刚起步,不知道错哪里了。
------解决方法--------------------------------------------------------
hello.no.username.error
少个引号.
------解决方法--------------------------------------------------------
web.xml配置了吗?
其实你简直就是没有很好利用到struts1.1以上版本的好处啊:),你的这种写法还以1.0的写法
------解决方法--------------------------------------------------------
我建议,你还是静下心来,myeclipse不是可以设置断点调试么?
你看看到底是哪一个地方出错了,然后再找解决办法
------解决方法--------------------------------------------------------
tag必须再web.xml中注册!
------解决方法--------------------------------------------------------
在struts-config.xml最后加入 <message-resources parameter="com.dacop.ApplicationResources" key="org.apache.struts.action.MESSAGE" />
其中ApplicationResources为你定义错误信息的资源文件名称