if (form == null) { if (log.isTraceEnabled()) { log.trace( " Creating new RegistrationForm bean under key " + mapping.getAttribute()); } form = new RegistrationForm(); if ("request".equals(mapping.getScope())) { request.setAttribute(mapping.getAttribute(), form); } else { session.setAttribute(mapping.getAttribute(), form); } } <p class="indent">
String username = (String) PropertyUtils.getSimpleProperty(form, "username"); String password = (String) PropertyUtils.getSimpleProperty(form, "password"); <p class="indent">
// 在此输入java代码 public static Object getSimpleProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (bean == null) { throw new IllegalArgumentException("No bean specified"); } if (name == null) { throw new IllegalArgumentException("No name specified"); } // Validate the syntax of the property name if (name.indexOf(NESTED_DELIM) >= 0) { throw new IllegalArgumentException ("Nested property names are not allowed"); } else if (name.indexOf(INDEXED_DELIM) >= 0) { throw new IllegalArgumentException ("Indexed property names are not allowed"); } else if (name.indexOf(MAPPED_DELIM) >= 0) { throw new IllegalArgumentException ("Mapped property names are not allowed"); } // Handle DynaBean instances specially if (bean instanceof DynaBean) { DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name); if (descriptor == null) { throw new NoSuchMethodException("Unknown property '" + name + "'"); } return (((DynaBean) bean).get(name)); } // Retrieve the property getter method for the specified property PropertyDescriptor descriptor = getPropertyDescriptor(bean, name); if (descriptor == null) { throw new NoSuchMethodException("Unknown property '" + name + "'"); } Method readMethod = getReadMethod(descriptor); if (readMethod == null) { throw new NoSuchMethodException("Property '" + name + "' has no getter method"); } // Call the property getter and return the value Object value = readMethod.invoke(bean, new Object[0]); return (value); } <p class="indent">
<action path="/editRegistration" type="org.apache.struts.webapp.example.EditRegistrationAction" attribute="registrationForm" scope="request" validate="false"> <forward name="success" path="/registration.jsp"/> </action> <p class="indent">
猜你喜欢
本站原创《复杂软件设计之道:领域驱动设计全面解析与实战》
其他人在看