關於struts中html:errors/的問題

tianhy發表於2004-12-11
檔案內容如下,為什麼我的<html:errors/>顯示不出來任何內容?而我手工寫的一段程式碼可以把Errors顯示出來。請大家幫忙,謝謝

<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java"%>
<%@ page import="org.apache.struts.action.ActionErrors"%>
<%@ page import="org.apache.struts.action.ActionError"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>

<html:html>
<head>
<title>File Upload</title>
</head>
<body>
<%
ActionErrors aes=(ActionErrors)request.getAttribute("org.apache.struts.action.ERROR");
if(aes!=null){
ActionError ae=(ActionError)aes.get().next();
%>
<%=ae.getKey()%>
<%
}
%>
<html:errors/>
<html:form action="/uploadFile" enctype="multipart/form-data">
<html:file property="file"/>
<html:submit value="Upload"></html:submit>
</html:form>
</body>
</html:html>

生成錯誤資訊的程式碼如下:
ActionErrors aes=new ActionErrors();
..........
ActionError ae=new ActionError(file.getFileName()+"上傳成功");
aes.add(ActionErrors.GLOBAL_ERROR,ae);
saveErrors(request,aes);
return new ActionForward(mapping.getInput());

相關文章