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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,551,671
Community Members
 
Community Events
184
Community Groups

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

2 answers

have you defined the servlet in the atlassian-plugin.xml?

0 votes
Fabian Lim
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 27, 2021

Hi @Chong Jing Hong

You may want to post this on the Atlassian Development community for a faster response: https://community.developer.atlassian.com/

Regards

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events