我有一个servlet类:
@MultipartConfig
public class TrainingServlet extends HttpServlet { .. }
在里面我有我的doPost方法:
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
String reqParm = req.getParameter("handler");
...
if ("parsefile".equals(reqParm)) {
Part part = req.getPart("file");
new ParseHotelFile().ParseHotelFile(part);
getServletContext().getRequestDispatcher("/training/uploadhotels.jsp").forward(req,resp);
}
}
我的问题是,每当“Part part = req.getPart(”file“)行时,”被调用,抛出nullpointerexception;我无法弄清楚为什么。我检查了我的servlet版本,它是3.0。
这是我的html表单:
<form method="post" enctype="multipart/form-data" action="/trainingservlet?handler=parsefile">
<table style="background-color:f0f0f0; padding:8px; border:1px solid #80bfff">
<tr>
<td>File to upload: <input style="background-color:#e0e0e0; border:1px solid #a0a0a0" type="file" name="file"></td>
</tr>
<tr>
<td><br><input type="submit" value="Import"></td>
</tr>
</table>
</form>