package onlyfun.caterpillar;在Action类别中,您可以如下面的方式来取值:
import java.util.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class UserForm extends ActionForm {
protected Map map = new HashMap();
public void setValue(String key, Object value) {
map.put(key, value);
}
public Object getValue(String key) {
return map.get(key);
}
public Map getMap() {
return map;
}
public void reset(ActionMapping mapping,
HttpServletRequest req) {
map.clear();
}
}
package onlyfun.caterpillar;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
UserForm userForm = (UserForm) form;
String name =
(String) userForm.getValue("name");
String password =
(String) userForm.getValue("password");
.....
}
}