How to enable jsp inside another jsp using javascript

I have a way out of the button. After logging out, I need to show another page. How to do it using JavaScript? Can anyone help me out?

My code is:

<s:form name="LogoutAction"
                id="LogoutAction" action="logout">
    <span class="inlayField2">
    <s:a href="logout" cssClass="planTabHeader" id="logoutId"> <img src="../../KY/images/common/header/lock.png" alt="logout" style="border: none;background-color: transparent;" /> &nbsp;Log out</s:a></span>
    </s:form> 

I tried this:

$('#logoutId').click(function(event) {

    $('#logoutdiv').load('ConfirmationPopup.jsp');
});
+5
source share
6 answers

You can use ajax to get html from the second jsp, and then add to the DOM or innerHTML element.

.Jsp homepage     

<span id=confirmSpan></span>
<script language="Javascript">
function xmlhttpPost(strURL, queryStr) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari, opera etc
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        alert("no ajax")
        return
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageConfirm(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(queryStr);
}


function updatepageConfirm(str){
    document.getElementById("confirmSpan").innerHTML = str;
}
function logout1(){
xmlhttpPost("confirm.html");//http://sel2in.com/pages/prog/html/ajax/confirm.html", "")
}
</script>
</head>
<body>
<form  id="search" action="/search" method="get">
<input type=button onclick=logout1() value=logout>
</form >

Example of a page with a confirmation code -> any valid html for a div can be confirm.jsp Take an action ... Are you sure?

// todo form here html span / pop up / script / css → as iframe

, - - ?

, id "logoutConfirmSpan", , ajax ( async → false, ) html innerHTML

html , .

. HTML div Ajax , ajax jQuery

:

HTML-

<span id = 'logoutConfirmSpan'> </span>
<script>
// call ajax, with the response call setHtmlForConfirm
function setHtmlForConfirm(req)
{
    document.getElementById('logoutConfirmSpan').innerHTML = req.responseText;
}
//req.responseText should have the html to show the confirm UI and form to submit yes/ no
</script>
+3

include JSP , . HTML- , CSS JavaScript. include , . - :

<div id="confirmPopup" style="display:hidden;">
      <%@ include file="ConfirmationPopup.jsp" %>
</div>
<script>
  $('#logoutId').click(function(event) {
   document.getElementById("confirmPopup").style.display="block";
  });
</script>
+2

GET HTML, .jsp. , Ajax jQuery :

$.get({
    url: "mysite.com/otherpage.jsp",
    data: "some data you want to send, optional",
    success: function(data, textStatus, jqXhr)//the response data, the ajax request status and the ajax request object itself {
        $('#someDiv').html(data);
    }
});
+2

1) <div id='someID'></div>

2) , javascript iframe jsp URL

3) iframe , ,

+1

, , : http://sel2in.com/pages/prog/html/ajax/aPage2.html1

<span id=confirmSpan></span>
<script language="Javascript">

function logout1(){
    iconfirmSpan = document.getElementById("confirmSpan")
    if (!confirmSpan){
        alert("Error no confirmSpan contact support!");
    }
    confirmSpan.innerHTML = "<iframe src=\"http://sel2in.com/pages/prog/html/ajax/confirm.html\" height=400 width=700></iframe>"
    //in real can keep height 1 width 1 and location off page if you want it just to load elements, scripts etc
}
</script>
</head>
<body>
<form  id="search" action="/search" method="get">
<input type=button onclick=logout1() value="Do Action">
</form >
0

AJAX - , .

AJAX jQuery (showcase → div), Struts2 Dojo , - , .

<%@ taglib prefix="s"  uri="/struts-tags"      %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>

<head>      
    <sx:head/>
    <script>
       function loadAjax(){
           var div = dojo.widget.byId("myDiv");
           div.href = "yourAjaxAction.action";
           div.refresh();
       }
    </script>
</head>
<body>
    <input type="button" 
           value="Include a JSP fragment dynamically" 
           onclick="loadAjax();"/>

    <sx:div id="myDiv"> </sx:div>

</body>

yourAjaxAction.action SUCCESS JSP, .

0

All Articles