【Java开源代码栏目提醒】:网学会员为广大网友收集整理了,ActionUtils.java,希望对大家有所帮助!
package com.opensource.blog.
web.action;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.*;
public class ActionUtils {
public ActionUtils() {
}
public synchronized static void addErrors(HttpServletRequest request, ActionMessages errors) {
if (errors == null) {
// bad programmer! *slap*
return;
}
// get any existing errors from the request, or make a new one
ActionMessages requestErrors = (ActionMessages) request.getAttribute(Globals.ERROR_KEY);
if (requestErrors == null) {
requestErrors = new ActionMessages();
}
// add incoming errors
requestErrors.add(errors);
// if still empty, just wipe it out from the request
if (requestErrors.isEmpty()) {
request.removeAttribute(Globals.ERROR_KEY);
return;
}
// Save the errors
request.setAttribute(Globals.ERROR_KEY, requestErrors);
}
}