我使用以下代码上传文件,目前它上传文件没有<..>
但我希望上传 XML 文件。如何上传文件?
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(isMultipart){
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try{
List<FileItem> fields = upload.parseRequest(request);
Iterator<FileItem> it = fields.iterator();
while (it.hasNext()) {
FileItem fileItem = it.next();
out.println(fileItem.getString());
}
}catch (FileUploadException e) {
e.printStackTrace();
}
}
}
编辑:例如,如果我上传的文件Screens><Screen
仅包含Screens>
输出。