Struts1.2-LazyValidateForm的使用-示例2

作者在 2006-12-12 08:37:00 发布以下内容

User.java

package test;

public class User {
 private String id;
 private String name;
 private String password;
 public String getId() {
  return id;
 }
 public void setId(String id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getPassword() {
  return password;
 }
 public void setPassword(String password) {
  this.password = password;
 }
}

index.jsp

<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<html>
 <head>
  <title>JSP for lazyForm form</title>
 </head>
 <body>
 <FORM name="form1" action="userAction.do?method=addUser" method="post" enctype="multipart/form-data">
    用户名<INPUT type="text" name="user.name" value="admin"><br>
    id<INPUT type="text" name="user.id" value="001"><br>
    密码<INPUT type="text" name="user.password" value="123"><br>
    文件<INPUT type="file" name="testfile" ><br>
    选择1<INPUT type="checkbox" name="c1" value="selected-1" checked >
    选择2<INPUT type="checkbox" name="c1" value="selected-2" checked ><br>
    非用户信息<INPUT type="text" name="other" value="other message"><br>
    <INPUT type="submit" value="addUser">
  </FORM>
    <logic:present name="lazyForm">
     <bean:write name="lazyForm" property="other"/>
    </logic:present>
 </body>
</html>

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
 <data-sources />
 <form-beans>
  <form-bean name="lazyForm" type="org.apache.struts.validator.LazyValidatorForm">
   <form-property name="c1" type="java.lang.String[]" />
   <form-property name="user" type="test.User" />
  </form-bean>

 </form-beans>

 <global-exceptions />
 <global-forwards />
 <action-mappings>
  <action attribute="lazyForm" input="/index.jsp" name="lazyForm" parameter="method" path="/userAction" scope="request" type="test.UserAction" validate="false">
   <forward name="addUser" path="/index.jsp" />
  </action>

 </action-mappings>

 <message-resources parameter="test.ApplicationResources" />
</struts-config>

UserAction.java

import org.apache.struts.actions.*;
import org.apache.struts.upload.*;

public class UserAction extends DispatchAction {
 public ActionForward addUser(ActionMapping mapping, ActionForm form,
   HttpServletRequest req

默认分类 | 阅读 2655 次
文章评论,共0条
游客请输入验证码
文章分类
最新评论