0

I have a jsp page that has 5 other pages.in my index page I have a special div in the middle where I want to load the other 4 pages when a button is clicked. Depending on the button clicked a specific page will load in a div in the index page. what I want to do here is load all the said pages in the div page in the home page with a button click. I tried several approach but I haven't really figure out how to fix this problem. in my index page the special div has a flash file playing and I have several buttons one of which is a product button when I click the product button want the special div to load the product.jsp. instead when I load the project the product.jsp is loaded together with the index page. I tried this

<form  action="workspace">
    <object id="swf" data="test.swf" type="application/x-shockwave-flash" >
        <param name="movie" value="test.swf">
        <p>You need Adobe Flash Player to view this content</p>
    </object>
    <div id="workspaceproducts" class="panel" style="display:hidden;">
          <%@ include file="products.jsp" %>
    </div>
</form>

<script>
$('#products').click(function(){
    $('#workspace').load(document.getElementById("workspaceproducts").style.display="block");
});
</script>
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • You can find answer and explanation here http://stackoverflow.com/questions/9110148/include-another-jsp-file – gowtham Jan 09 '14 at 09:15

3 Answers3

1

You need to use a dynamic include to make it work

<jsp:include page="..." />
Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
  • how to i connect it to a button? –  Jan 09 '14 at 09:17
  • that's another question. i didn't understand though – Keerthivasan Jan 09 '14 at 09:19
  • my problem is like this in my home page i have 4 other buttons lets name it button 1 button 2 etc. im my home page i have a div called red_div in my red_div at home it has a flash, now when i click button 1 i want red_div to contain page 1 and when i click button 2 i want red_div to contain page 2 how do i achieve this? –  Jan 09 '14 at 09:23
  • You need to push the appropriate page via javascript on button click – Keerthivasan Jan 09 '14 at 09:27
  • i know that i need to push the corresponding button but i really dont know how to do you have any more suggestion please make it cleare –  Jan 09 '14 at 09:37
0

You can't include your JSP in div on the client side because it's a server-side technology.The include would already have happened on the server side before the page was sent to the client.

You May use Ajax to load your JSP page inside div.

For Example :

<input type="button" onclick="loadPage('JspFileName.jsp')" />  

function loadPage(fileName)  
{

   $.ajax({
         type: "POST",
         url: fileName,                   
         cache: true,
         success: function(response) {
             $('#workspace').html(response);
          }
     });  
}
Yagnesh Agola
  • 4,556
  • 6
  • 37
  • 50
  • how do i do it in this approach? –  Jan 09 '14 at 09:25
  • im looking at it but i cant understand it how do the button 1 load page 1 in this code?sorry but im new in struts –  Jan 09 '14 at 09:41
  • Add `onclick` event to your button, call javascript function and passed your jsp file name to function, give this file name to ajax call.see updated answer. – Yagnesh Agola Jan 09 '14 at 09:47
  • mate i've been trying to figure out about the error i've made since yesterday with your code but i cant so here i am again it says $ is not defined in the line $.ajax({ –  Jan 11 '14 at 04:43
0

Since you have tagged your question with struts, struts provides you a very genuine and correct way to include one jsp into another and that too more than one at a time. This tutorial will guide properly. I have used it extensively and even for drag and drop! from one page to another :)

DarkHorse
  • 2,740
  • 19
  • 28
  • this tutorial only cover static include i mean include header and footer what i want is to include a page when a button is clicked but its the close to what i want –  Jan 11 '14 at 04:38
  • sir darkhorse can you check my question http://stackoverflow.com/questions/20986116/struts-2-load-a-page-in-div – Giant Jan 11 '14 at 04:46
  • @satinekianne Struts tiles also have functions to have dynamic includes. But for your functionality all you have to do is write an extra tile for button click i.e an action on button click which will call a particular tile definition having you concerned pages included. According to that tutorial, you can have more than 1 baselayout pages. I had 16 in my project :P each having different layouts as per user selection. For dynamic includes here [documentation](https://tiles.apache.org/2.2/framework/index.html) for tiles – DarkHorse Jan 11 '14 at 05:19
  • gonna check it out get back on you on it bro –  Jan 11 '14 at 05:30