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

askr askr 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
插入一条信息,如果没有填写其中的两项,应该回到表单,显示错误,但如果加上<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>
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
askr
Web 开发 81,108 成员 341,721 内容