Some JSP files are required to run in two modes, standalone and inside a <div> element within nidp_latest.jsp. These JSP files must be able to detect the appropriate mode.
The detection process is different for JavaScript and Java. JavaScript runs on the user’s web browser whereas, Java runs on the server.
When a JSP file is loaded into a <div> element in nidp_latest.jsp, the HTML elements, such as <html>, <head>, and <body> are not necessary. Also, the nidp_latest.jsp implementation can assume that the provided JavaScript functions are available for use. For example, the function setGlobalMessage(strMessage) can be called without any problem.
When the same JSP file is loaded standalone, it must provide all required HTML elements to create a proper HTML document. It cannot rely on any of JavaScript and CSS that nidp_latest.jsp provides.
The nidp_latest.jsp implementation includes the empty DOM element:
<div id="runningInEndUserLoginEnvironment" style="display: none"></div>
The JSP JavaScript code can query for the existence of this DOM element. If this element exists, the JSP runs inside the nidp_latest.jsp environment.
var proofOfEndUserEnvironment= document.getElementById('runningInEndUserLoginEnvironment');
The JavaScript function getToContent(strUrl strTargetDivId) adds an HTTP request parameter that names the identifier of the <div> element that is the target of the request.
strUrl = updateQueryString( "<%=NIDPConstants.HTTP_REQUEST_PARAM_NAME_UIDESTINATION%>", "<%=NIDPConstants.HTTP_REQUEST_PARAM_NAME_UIDESTINATION_VALUE_CONTENTDIV%>", strUrl);
The JSP Java code runs on the server and the request is the JQuery AJAX HTTP Get request sent by getToContent(). Therefore, the Java code can query the existence and value of the NIDPConstants.HTTP_REQUEST_PARAM_NAME_UIDESTINATION request parameter. If it exists, the Java code can determine the target <div> element and know that the current request is an AJAX request produced by getToContent().
String strUIDestinationId = (String) request.getParameter(NIDPConstants.HTTP_REQUEST_PARAM_NAME_UIDESTINATION); if (!StringUtil.isDefined(strUIDestinationId) || (!strUIDestinationId.equals(NIDPConstants.HTTP_REQUEST_PARAM_NAME_UIDESTINATION_VALUE_CONTENTDIV))) { bProofOfEndUserEnvironment = false; }