Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to render velocity template in servlet?

I have a servlet class that handles csv file uploads. I want the plugin to render a velocity template after the upload is complete to say that the file upload has been completed. Here is my code so far:

public class BulkUserCreatorToolServlet extends HttpServlet{
private final TemplateRenderer renderer;    
private final WebResourceManager webResourceManager;
public BulkUserCreatorToolServlet(TemplateRenderer renderer, WebResourceManager webResourceManager){        
this.renderer = renderer;        
this.webResourceManager = webResourceManager;    
}

    @Override    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOExceptionServletException {
        // 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()){                
//handle file            
}
            

Map<StringObject> context = new HashMap<StringObject>();            
context.put(
"testname""testvalue");                        
response.setContentType(
"text/html;charset=UTF-8");            
response.getWriter().print(renderer.render(
"plugin-key","response-page.vm", context));        
}
        
catch(FileUploadException e){            
e.printStackTrace();
        
}
        
catch(Exception e){            
e.printStackTrace();
        
}
    
}

}

 Upon upload, Page Not Found always shows. What did I do wrong? Thank you

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

🏑 Atlympic Event: Confluence

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

293 views 12 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you