首页 > 代码库 > beanutils中类型转换
beanutils中类型转换
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="http://www.mamicode.com/张三" name="name" >
<input type="text" value="http://www.mamicode.com/李四" name="name" >
<input type="submit" value="http://www.mamicode.com/提交" >
</form>
beanutils中类型转换