怎么一加就转发到错误处理页面errorpage.jsp了?

askr 2004-10-23 06:04:22
插入一条信息,如果没有填写其中的两项,应该回到表单,显示错误,但如果加上<html:errors/>,就直接转发到错误处理页面了,我把源代码的页面和actionform复制了过来,也还是这样,错误原因显示的还是null,去掉就好了,但源代码的例子运行却正常,这是为什么?
ActionForm:
package addressbook.forms;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/**
* <strong>InsertForm</strong> handles the form
* that the user will use to insert a new Address into
* the database.
*/

public final class InsertForm extends ActionForm {

private String name = null;
private String phone = null;
private String address = null;
private String page=null;

public String getName() {
return name;
}
public String getPhone() {
return phone;
}
public String getAddress() {
return address;
}

public String getPage(){
return page;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
int numPage=0;
try{ numPage=new Integer(request.getParameter("page")).intValue();}catch(Exception e){}
if(numPage==1){
name=null;
phone=null;
}
if(numPage==2){
address=null;
}
page=null;
}

public void setName(String name) {
this.name = name;
}
public void setPhone(String phone) {
this.phone= phone;
}
public void setAddress(String address) {
this.address = address;
}

public void setPage(String page){
this.page=page;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {

ActionErrors errors = new ActionErrors();
int numPage=0;
try{ numPage=new Integer(page).intValue();}catch(Exception e){}
if(numPage==1){
if (((name == null) || (name.length() < 1)))
errors.add("name", new ActionMessage("error.name.required"));
if(((phone == null)|| (phone.length() < 1)))
errors.add("phone", new ActionMessage("error.phone.required"));
}

if(numPage==2){
if(((address == null)|| (address.length() < 1)))
errors.add("address", new ActionMessage("error.address.required"));
}
return errors;

}
}
jsP:taglibs.jsp专门声明引用哪些tag,错误页名,<app:validateSession/>校验是否登录
<%@ include file="taglibs.jsp" %>
<app:validateSession/>
<html:errors/>
<html:form action="/insert1.do" focus="title">
<html:hidden property="page" value="1"/>
<center>
<table border="0" cellspacing="2" cellpadding="2" width="100%">
<tr>
<td align="right"> <bean:message key="prompt.name"/></td>
<td><html:text property="name" size="25" maxlength="25"/></td>
</tr>
<tr>
<td align="right"> <bean:message key="prompt.phone"/></td>
<td><html:text property="phone" size="25" maxlength="10"/></td>
</tr>
<tr>
<td align="right">
<html:submit property="submit" value="next">
<bean:message key="button.insert"/>
</html:submit>
</td>
<td align="left">
<html:reset >
<bean:message key="button.reset"/>
</html:reset>
</td>
</tr>
</table>
</center>
</html:form>
<html:link forward="mainMenu"><bean:message key="goto.mainMenu"/></html:link>
...全文
192 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fashchina 2004-10-24
  • 打赏
  • 举报
回复
up
askr 2004-10-24
  • 打赏
  • 举报
回复
书上说要被废弃,被actionmessage取代,
kui 2004-10-23
  • 打赏
  • 举报
回复
1.2.4里还有ActionError这个类,只是不建议,用起来不太灵活,ActionMessage是ActionError的基类,用起来灵活些,但也得多写点多东。
askr 2004-10-23
  • 打赏
  • 举报
回复
ActionMessage改成ActionError,倒是一切正常,不过1.2里就要废弃此类,用着总不是个事
askr 2004-10-23
  • 打赏
  • 举报
回复
to kui:
validate能有什么问题,它只是返回一个错误集,错误集也不应该导致页面错误。况且,这是例子的源代码
ynniebo 2004-10-23
  • 打赏
  • 举报
回复
<html:errors/>不是转发到错误处理页面errorpage.jsp了的吧.他显示你的validate里面的错误信息吧......你要转向错误页面是要通过forward或其它的方式来处理的.
kui 2004-10-23
  • 打赏
  • 举报
回复
很可能是validate函数的问题,你自己详细分析一下,把不你不确定的代码先掉去,或全部去掉看是否是validate函数的问题,如果是就不断去掉直到能通过,这时也就找到了出错之处。

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧