标题:html:error 不显示错误信息[已解决]
只看楼主
atsjun
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-9-8
 问题点数:0 回复次数:2 
html:error 不显示错误信息[已解决]

郁闷 搞了一天了都没搞定,大家帮帮忙啊
以下是我的代码

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编辑过]

搜索更多相关主题的帖子: jakarta uri apache 
2007-09-30 13:34
atsjun
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-9-8
得分:0 
问题解决  原来是struts1.1的问题用了1.2就出来了

2007-09-30 15:15
缘吇弹
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:地球
等 级:版主
威 望:43
帖 子:3038
专家分:27
注 册:2007-7-2
得分:0 
呵呵,解决了就好.

Repeat  Life=Study;Until (death);
2007-09-30 15:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-174289-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.074437 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved