Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1.  
  2. package webcontroller;
  3.  
  4. import entities.Post;
  5. import entities.User;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import javax.ejb.EJB;
  9. import javax.servlet.ServletException;
  10. import javax.servlet.annotation.MultipartConfig;
  11. import javax.servlet.annotation.WebServlet;
  12. import javax.servlet.http.HttpServlet;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import wService.AbstractFacade;
  16. import wService.PostFacadeREST;
  17.  
  18. /**
  19. *
  20. * @author congthanhptnk
  21. */
  22. @MultipartConfig(location= "/var/www/html/storage")
  23. @WebServlet(name = "UpLoadPic", urlPatterns = {"/UpLoadPic"})
  24. public class UpLoadPic extends HttpServlet {
  25.  
  26. @EJB
  27. private PostFacadeREST postFacadeREST;
  28.  
  29. /**
  30. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  31. * methods.
  32. *
  33. * @param request servlet request
  34. * @param response servlet response
  35. * @throws ServletException if a servlet-specific error occurs
  36. * @throws IOException if an I/O error occurs
  37. */
  38. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  39. throws ServletException, IOException {
  40. response.setContentType("text/html;charset=UTF-8");
  41.  
  42. }
  43.  
  44. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  45. /**
  46. * Handles the HTTP <code>GET</code> method.
  47. *
  48. * @param request servlet request
  49. * @param response servlet response
  50. * @throws ServletException if a servlet-specific error occurs
  51. * @throws IOException if an I/O error occurs
  52. */
  53. @Override
  54. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  55. throws ServletException, IOException {
  56. processRequest(request, response);
  57. }
  58.  
  59.  
  60. /**
  61. * Handles the HTTP <code>POST</code> method.
  62. *
  63. * @param request servlet request
  64. * @param response servlet response
  65. * @throws ServletException if a servlet-specific error occurs
  66. * @throws IOException if an I/O error occurs
  67. */
  68. @Override
  69. protected void doPost (HttpServletRequest request, HttpServletResponse response)
  70. throws ServletException, IOException {
  71. processRequest(request, response);
  72. request.getPart("upFile").write(request.getPart("upFile").getSubmittedFileName());
  73. String pictureLink = "10.114.34.13/storage/" + request.getPart("upFile").getSubmittedFileName();
  74. String title = request.getParameter("title");
  75. String caption = request.getParameter("caption");
  76. int id = Integer.parseInt(request.getParameter("id"));
  77. postFacadeREST.createPost(title, caption, pictureLink, id);
  78.  
  79. }
  80.  
  81. /**
  82. * Returns a short description of the servlet.
  83. *
  84. * @return a String containing servlet description
  85. */
  86. @Override
  87. public String getServletInfo() {
  88. return "Short description";
  89. }// </editor-fold>
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement