首页 > 其他 > 详细

beanutils中类型转换

时间:2014-10-27 06:52:17      阅读:244      评论:0      收藏:0      [点我收藏+]

public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        MyBean myBean=new MyBean();
        HashMap map=new HashMap();
        Enumeration<String> enumeration=request.getParameterNames();
        while (enumeration.hasMoreElements()) {
            String name = (String) enumeration.nextElement();
            map.put(name, request.getParameterValues(name));
        }
        try {
            BeanUtils.populate(myBean, map);
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(map);
    }

 

index.jsp

<form action="bean" method="post">
        <input type="text" value="张三" name="name" >
        <input type="text" value="李四" name="name" >
        <input type="submit" value="提交" >
    </form>

beanutils中类型转换

原文:http://www.cnblogs.com/danmao/p/4053360.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!