How to open window in a new tab via JSP?

William Hsu June 28, 2021

Hi,

We have an external third party report that integrated with Confluence 7.0.3. We created a JSP file and set the JSP file as a space shortcut for a specific space. When user click the shortcut, system will pass the current login account with post method through the JSP file and then open a window in new tab. The login account is used to read allowed Confluence pages in the external report and the post method is used for security concern. This way works fine before upgrade Confluence.

After we upgraded to Confluence 7.4.9, it does not work anymore. The JSP does not open new window due to window.open() returns null. And I also find a message "Use of `window._` through AUI is deprecated and will be removed in AUI 9.0" in browser console.

Here is my question: Is there any solution to pass the current login account to external third party page with post method? Please help. Thank you!

Below is the JSP for your reference.

<%@page import="com.atlassian.crowd.embedded.api.User" %>
<%@page import="java.security.Principal" %>

<%

// prevent browser cache jsp
response.setHeader("Pragma", "No-cache"); // HTTP 1.0
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setDateHeader("Expires", -1); // proxies

String _user = "";

try {
_user = ((Principal)session.getAttribute("seraph_defaultauthenticator_user")).getName();
} catch(Exception e) {
}
%>


<html>

<head>

<title>Comparison Report</title>

<script>
function openWindowWithPost(url, name, keys, values)
{
var newWindow = window.open(url, name);

if (!newWindow) return false;

var html = "";
html += "<html><head></head><body><form id='formid' method='post' action='" + url + "'>";
if (keys && values) html += "<input type='hidden' name='" + keys + "' value='" + values + "'/>";
html += "</form><script type='text/javascript'>document.getElementById('formid').submit();";
html += "<\/script></body></html>".toString().replace(/^.+?\*|\\(?=\/)|\*.+?$/gi, "");

newWindow.document.write(html);
return newWindow;

}

openWindowWithPost("https://xxx.xxx.xxx/CmpReport.aspx", "_blank", ["username"], ["<%= _user %>"]);

window.location = window.document.referrer;
</script>
</head>

</html>

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events