xskit
xskit

Reputation: 431

JSP dynamically change include page

I have a <div> tag:

<div id="content">
    <jsp:include page="some.jsp"/>
</div>

Also I have a few buttons:

<input type="submit" name="btn1" value="Page1">
<input type="submit" name="btn2" value="Page2">

I need when I click btn1 some.jsp changes to page1.jsp and to page2.jsp when click btn2.

Upvotes: 1

Views: 4020

Answers (3)

Anas Elbenney
Anas Elbenney

Reputation: 53

Im using this solution : My form is :

 <FORM>
  <select name="choix">  
                    <option  value="choix 1">choix 1</option> 
                    <option value="choix 2">choix 2</option>
                    <option value="choix 3">choix 3</option>   
                   
                
        </select>
                
            <input type="submit" />
</FORM> 

and im using this in the same jsp page to include a page as what i select in that form:

     <% 
     Ch = request.getParameter("choix");
     %>  
    
         <div id="inculde_page">
             <jsp:include page="<%= "layouts/" + Ch + ".jsp" %>" />
         </div>

Upvotes: 0

Abdelhak
Abdelhak

Reputation: 8387

1- Instead of using static include, you can use dynamic include, then you can do something like this:

 <jsp:include page="${somePage}" flush="true" />

2- Use javascript to change the action of the form depending on the button you click:

 <input type="submit" value="Page1" name="btn1" 
  onclick="document.forms[0].action = 'somePage.jsp'; return true;" />

Upvotes: 1

Ignacio Chiazzo
Ignacio Chiazzo

Reputation: 1077

Use dynamic include,

<jsp:include page="<%= myVariable %>" flush="true" />

Pd: Take a look a flush http://www.coderanch.com/t/484149/JSP/java/flush-true-jsp-include-tag.

Upvotes: 2

Related Questions