Hi, I have a plugin that allows users to upload a csv file. After the upload is completed, I would like the plugin to render a velocity template that says upload successful. How do I do so?
Servlet class:
public class BulkUserCreatorToolServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
// Configure a repository (to ensure a secure temp location is used)
ServletContext servletContext = this.getServletConfig().getServletContext();
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
factory.setRepository(repository);
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
try{
//Parse the request to get file items
List<FileItem> fileItems = upload.parseRequest(request);
// Process the uploaded items
Iterator<FileItem> iter = fileItems.iterator();
while(iter.hasNext()){
// file handling
}
}
catch(FileUploadException e){
e.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
}