怎么一加就转发到错误处理页面errorpage.jsp了?
插入一条信息,如果没有填写其中的两项,应该回到表单,显示错误,但如果加上<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>
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>
...全文
相关推荐
JSP学习之异常处理实例分析
而errorPage属性用于指定当前页面发生错误时应跳转到的错误处理页面。
Servlet源代码.pdf
**JSP表达式**:在JSP页面中,可以使用 `${}` 符号来访问存储在会话中的属性,例如 `${success}` 或 `${errors}`,这些信息会被显示在页面上。
J2EE中Struts中四种解决中文乱码问题的方法
<html:text property="name" /> <html:submit value="提交" /></html:form>```#### 方法四:通过ActionServlet配置**原理介绍
政府科技管理者如何提升区域科技成果转化成功率?.docx
政府科技管理者如何提升区域科技成果转化成功率?
LangGraph与Graphviz集成:生成高质量静态图
内容概要:展示如何将LangGraph图导出为Graphviz DOT格式,生成PNG/SVG。通过自定义布局和样式,呈现清晰的流程图。对比Mermaid,讨论适用场景。 0533zbyy.com 0595ty.cn www.zh-casting.com yobest2.com 10cd.cn


Web 开发
