这是实体类字段
package domain;
public class Student {
private String stuNumber;
private String name;
private String sex;
private int age;
private String address;
private String phoneNumber;
private String major;
private Integer credit;
public Student() {
}
这是servlet populate哪一行报错
//获取表单信息
Map<String, String[]> requestMap = request.getParameterMap();
//封装数据
Student student = new Student();
try {
BeanUtils.populate(student,requestMap);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
//调用添加学生方法
ss.insertStudent(student);
System.out.println(student);
//添加完成后重定向到listServlet
response.sendRedirect(request.getContextPath()+"/listServlet");
这是前端
<body>
<div class="container">
<center><h3>添加学生</h3></center>
<form action="${pageContext.request.contextPath}/insertStudentServlet" method="post">
<div class="form-group">
<label for="name">姓名:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="请输入姓名">
</div>
<div class="form-group">
<label>性别:</label>
<input type="radio" name="sex" value="男" checked="checked"/>男
<input type="radio" name="sex" value="女"/>女
</div>
<div class="form-group">
<label for="age">年龄:</label>
<input type="text" class="form-control" id="age" name="age" placeholder="请输入年龄">
</div>
<div class="form-group">
<label for="address">籍贯:</label>
<select name="address" class="form-control" id="address">
<option value="广东">广东</option>
<option value="广西">广西</option>
<option value="湖南">湖南</option>
</select>
</div>
<div class="form-group">
<label for="phoneNumber">电话:</label>
<input id="phoneNumber" type="text" class="form-control" name="qq" placeholder="请输入手机号"/>
</div>
<div class="form-group">
<label for="major">专业:</label>
<input id="major" type="text" class="form-control" name="major" placeholder="请输入专业"/>
</div>
<div class="form-group">
<label for="credit">学分:</label>
<input id="credit" type="text" class="form-control" name="credit" placeholder="请输入学分"/>
</div>
<div class="form-group" style="text-align: center">
<input class="btn btn-primary" type="submit" value="提交" />
<input class="btn btn-default" type="reset" value="重置" />
<input class="btn btn-default" type="button" value="返回" />
</div>
</form>
</div>
</body>
报错信息
javax.servlet.ServletException: Servlet执行抛出一个异常
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
根本原因。
java.lang.NoClassDefFoundError: org/apache/commons/collections/FastHashMap
org.apache.commons.beanutils.PropertyUtilsBean.getPropertyDescriptor(PropertyUtilsBean.java:964)
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:935)
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:823)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:431)
web.InsertStudentServlet.doPost(InsertStudentServlet.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)