Reputation: 67
I have a jsp page that loads other pages into a modal div. I am not able to get a variable recognized in the other pages. I am sure the problem is quite simple to solve, any help?
Here is the variable page1 in the main page:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.page.SelectPage" %>
<% SelectPage page1 = (SelectPage)request.getAttribute("page"); %>
I have a simple modal div defined
<div class="container modal" id="mymodal" style="height:70%"></div>
When someone click on a link I load the modal using jquery.load
<a class="btn btn-outline modal-trigger" onclick="modalNavigate('mytopic');">Single Modal Navigation</a>
<script>
function modalNavigate(navPage){
$("#mymodal").load(navPage + ".jsp");
}
</script>
However when the navpage is loaded the variable page1 is not recognized
Upvotes: 0
Views: 305
Reputation:
Problem is that request.getAttribute("page")
loses its scope when you use $.load()
as it leads to another request.
Option 1. Just use session instead of request to get the page
object.
Option 2. Using $.ajax instead of $.load with additional parameters from request page object
.
Upvotes: 1
Reputation: 189
Do an ajax request to the server, return the data to the JSP and in success of AJAX request add the data to the modal popup.
Upvotes: 0