SHARE
TWEET

Untitled

a guest Nov 23rd, 2015 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import javax.servlet.RequestDispatcher;
  2. import javax.servlet.annotation.WebServlet;
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7.  
  8. @WebServlet("/index.vm")
  9. public class VelocityServlet extends javax.servlet.http.HttpServlet {
  10.  
  11.     @Override
  12.     protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
  13.             throws javax.servlet.ServletException, IOException {
  14.  
  15.         try{
  16.  
  17.             List<User> users = new ArrayList<>();
  18.  
  19.             for (int i = 0; i < 5; i++){
  20.  
  21.                 User user = new User("Name " + i, "Adresse " + i);
  22.                 users.add(user);
  23.             }
  24.  
  25.             request.setAttribute("users", users);
  26.             request.setAttribute("foo2", "foobar");
  27.             request.setAttribute("foo1", "foobo");
  28.  
  29.             RequestDispatcher requestDispatcher = request.getRequestDispatcher("/index.vm");
  30.             requestDispatcher.forward(request, response);
  31.  
  32.         } catch (Exception ex){
  33.             System.out.println(ex);
  34.         }
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top