如何从另一个jsp页面刷新jsp页面?

时间:2017-03-14 03:43:17

标签: javascript java jsp

我有两个jsp页面。 groups.jsp addGroup.jsp

通过单击groups.jsp中的按钮打开addGroup JSP页面,单击 addGroup.jsp 中的“确定”按钮后,我想刷新 groups.jsp 即可。怎么可能呢?

addGroup.jsp

<script type="text/javascript">
   function refresh() {                         
        //Refresh page implementation here
        window.close();
    }
</script>

//some code here
<table>
  <tr>
  <td>
     <h:commandButton id="buttonOK" value="#{common.ok}" type="button" styleClass="button" onclick="submitForm(); refresh();"/>
  <td>
  </tr>
</table>
//some code here

1 个答案:

答案 0 :(得分:3)

您可以使用window.opener

  

objRef = window.opener;

     

返回对打开当前窗口的窗口的引用。

在你的情况下试试这个:

if (!window.localStorage) {
  window.localStorage = {
    getItem: function (sKey) {
      if (!sKey || !this.hasOwnProperty(sKey)) { return null; }
      return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
    },
    key: function (nKeyId) {
      return unescape(document.cookie.replace(/\s*\=(?:.(?!;))*$/, "").split(/\s*\=(?:[^;](?!;))*[^;]?;\s*/)[nKeyId]);
    },
    setItem: function (sKey, sValue) {
      if(!sKey) { return; }
      document.cookie = escape(sKey) + "=" + escape(sValue) + "; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/";
      this.length = document.cookie.match(/\=/g).length;
    },
    length: 0,
    removeItem: function (sKey) {
      if (!sKey || !this.hasOwnProperty(sKey)) { return; }
      document.cookie = escape(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
      this.length--;
    },
    hasOwnProperty: function (sKey) {
      return (new RegExp("(?:^|;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
    }
  };
  window.localStorage.length = (document.cookie.match(/\=/g) || window.localStorage).length;
}


function getSavedPages() {
  var page = window.localStorage.getItem('hashStoreKeyValues');
  if(page==null){
   return [];
  } 
    var idContainer = JSON.parse(unescape(page));
    return  idContainer;
}

function savePage(ID, name) {

   var currentStatus =  JSON.parse(unescape(window.localStorage.getItem('hashStoreKeys')));
   var currentStatusValues =  JSON.parse(unescape(window.localStorage.getItem('hashStoreKeyValues')));
   if(currentStatus == null){
      currentStatus = [];
   } 

   if(currentStatusValues == null){
      currentStatusValues = {};
   } 

   if (currentStatus.indexOf(ID) === -1) { 
      currentStatus.push(ID); 
      currentStatusValues[ID] = name;
   }
   window.localStorage.setItem("hashStoreKeys", JSON.stringify(currentStatus));
   window.localStorage.setItem("hashStoreKeyValues", JSON.stringify(currentStatusValues));
}