Struts1.2懒人就用LazyValidatorForm

懒的境界在于操作懒而脑袋不能懒
想偷懒就要多看多想
懒得废话,看配置和程序吧


struts-config.xml


 
 
  
   
   
  

 

 
 
 
                  input="index.jsp"
                name="lazyForm" 
                parameter="method"
                path="/userAction"
                scope="request"
                type="test.UserAction"
                validate="false">

   
  

 

 

JSP
 
<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>

 
  JSP for lazyForm form
 
 
 


    用户名

    年龄

    密码

    文件

    选择1
    选择2

    非用户信息

   
   

   
   
   

 


Action
package test;

import javax.servlet.http.*;

import org.apache.commons.beanutils.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.*;
import org.apache.struts.upload.*;

public class UserAction extends DispatchAction {

 /**
  * Method execute
  *
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return ActionForward
  */
 public ActionForward addUser(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  DynaBean lazyForm = (DynaBean) form;
  System.out.println(lazyForm.get("c1"));
  System.out.println(((FormFile) lazyForm.get("testfile")).getFileSize());
  System.out.println(lazyForm.get("user"));
  return mapping.findForward("addUser");
 }

}

 

你可能感兴趣的:(Java,高级)