0

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

4
  • where do you invoke this modalNavigate()? Commented May 25, 2018 at 11:09
  • Its attached to a button to start the process. After that it will be attached to links contained in the modal page to load another page into the same modal. <a class="btn btn-outline pink accent-3 modal-trigger" onclick="modalNavigate('b3tztopic');">Single Modal Navigation</a> Commented May 26, 2018 at 1:03
  • Kindly edit your post with that additional code for better help. Commented May 26, 2018 at 2:23
  • Actually the real problem is not being able to access the request attribute of the parent window from inside the modal loaded by jquery.load. Commented May 26, 2018 at 4:40

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

3 Comments

$.load() does exactly the same thing
I am using the embedded java variable page1 to get access to the server across all the modals. I would like to have that access so I do not have to make a series of ajax calls and process the results into objects.
The problem is page1 is not in scope for the results of the $.load()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.