1.導(dǎo)包
commons-beanutils-1.8.3.jar
commons-logging-1.1.1.jar
2.封裝
/**
* 1.獲取參數(shù)集(jsp頁面的input的name要和javabean的屬性名對應(yīng))
* 2.調(diào)用方法分裝成javabean(自動轉(zhuǎn)型)
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/**
* 1.獲取參數(shù)集(jsp頁面的input的name要和javabean的屬性名對應(yīng))
*/
Map<String, String[]> map = new HashMap<String, String[]>(
request.getParameterMap());
User user = new User();
try {
/**
* 2.調(diào)用方法分裝成javabean
*/
BeanUtils.populate(user, map);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
User類
jsp表單部分