郁闷 搞了一天了都没搞定,大家帮帮忙啊
以下是我的代码
testError.jsp
----------------------
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html>
<head>
<title>
test
</title>
</head>
<body bgcolor="#ffffff">
<h1>
test.jsp
</h1>
<html:form action="/testError.do" method="post">
<html:text property="name" />
<html:errors property="name"/>
<br>
<html:submit value="Submit" property="Submit"/>
</html:form>
</body>
</html:html>
----------------------------------------------
struts-config.xml部分代码
----------------------------------------------
...
<form-beans >
<form-bean name="testForm" type="test.TestForm" />
</form-beans>
...
<action-mappings >
....
<action input="/test/testError.jsp" name="testForm" path="/testError" scope="request" type="test.TestAction">
<forward name="test" path="/test/testError.jsp" />
</action>
</action-mappings>
...
<message-resources parameter="ApplicationResources"/>
-----------------------------------------------
TestForm.java
-----------------------------------------------
package test;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
public class TestForm extends ActionForm {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest ServletRequest) {
ActionErrors errors = new ActionErrors();
if (name == null || name.trim().length() == 0)
errors.add("name", new ActionError("test.jsp.name.error"));
return errors;
}
public void reset(ActionMapping actionMapping,
HttpServletRequest servletRequest) {
}
}
-------------------------------
TestAction.java
-------------------------------
public class TestAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
return mapping.findForward("test");
}
}
------------------------------------
ApplicationResources.properties
------------------------------------
test.jsp.name.error=name must is not null!
------------------------------------
每次虽然跳转回来了 可是就是不显示错误信息....郁闷中ORZ
[此贴子已经被作者于2007-9-30 15:15:27编辑过]
----------------解决方案--------------------------------------------------------
问题解决 原来是struts1.1的问题用了1.2就出来了
----------------解决方案--------------------------------------------------------
呵呵,解决了就好.
----------------解决方案--------------------------------------------------------