-1

I'm building a dynamic web editor in java using jsp, servlets and websockets. I want to have shared edition functionality but I have no idea of how to implement it. My objective is that, when a user creates a document, he could share it. And the user he shared the document can modify it when he gets connected and the changes to be simultaneaous between different users. I tried the method below which consists of setting the new document as a session attribute for the user who creates the document. But I don't know how to pass it to the jsp to be a session attribute for the user to whom it is shared(I don't even know if it is a good practice).

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
        String docName = request.getParameter("docTitle");
        // get the user who created the doc id
        User u = (User)request.getSession().getAttribute("currentUser");
        
        DocumentDao docDao = new DocumentDao();
        Document doc = new Document(u,docName);
        try {
            if(docDao.exist(doc)) {
                System.out.println("Document déjà existant");
                getServletContext().getRequestDispatcher("Home").forward(request, response);
            }
            else {
                doc.addUser(u);
                docDao.createDoc(doc);
                request.getSession().setAttribute("doc", doc);      
                getServletContext().getRequestDispatcher("/WEB-INF/views/document.jsp").forward(request, response);
            }
        } catch (SQLException | ServletException | IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }

Thank you for your response !!!

manu
  • 7
  • 3

0 Answers0