How to Load external Div that has a dynamic content using ajax and jsp/servlets ?
        Posted  
        
            by A.S al-shammari
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by A.S al-shammari
        
        
        
        Published on 2010-04-25T19:50:03Z
        Indexed on 
            2010/04/25
            19:53 UTC
        
        
        Read the original article
        Hit count: 330
        
I need to use ajax feature to load external div element ( external jsp file) into the current page. That JSP page contains a dynamic content - e.g. content that is based on values received from the current session.
I solved this problem , but I'm in doubt because I think that my solution is bad , or maybe there is better solution since I'm not expert.
I have three files:
Javascript function that is triggered when a element is clicked, it requests html data from a servlet:
$("#inboxtable tbody tr").click(function(){
});var trID = $(this).attr('id'); $.post("event?view=read",{id:trID}, function(data){ $("#eventContent").html(data); // load external file },"html"); // typeThe servlet "event" loads the data and generates HTML content using include method :
String id = request.getParameter("id"); if (id != null) { v.add("Test"); v.add(id); session.setAttribute("readMessageVector", v); request.getRequestDispatcher("readMessage.jsp").include(request, response); }The readMessage jsp file looks like this:
<p> Text: ${readMessageVector[0]} </p> <p> ID: ${readMessageVector[1]} </p>My questions
Is this solution good enough to solve this problem - loading external jsp that has dynamic content ?
Is there better solution ?
© Stack Overflow or respective owner