#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Singapore
    Posts
    6
    Rep Power
    0

    Can I close popup window in JSP?


    I'm currently doing a web application that have a button. When onClick, a popup window will appears.

    Html :
    <html>
    <head>
    <title>Add Country</title>
    <SCRIPT language="JavaScript">
    function popupwin(val,del)
    {
    if(del=='00')
    window.open('presenceCountries.jsp?ctype='+val+'&del=00','','width=600,height=500,scrollbars=yes');
    else
    {
    document.addCountry.action ='presenceCountries.jsp?ctype='+val+'&del='+del;
    document.addCountry.submit();
    }
    }
    </SCRIPT>
    </head>
    <body >
    <form action="" method="post" name="addCountry" >

    <input type="button" value="Add Countries" name="addCountry" class="formbutton" onClick="popupwin('pp','00')">
    </body>
    </html>

    presenceCountries.jsp codes:

    <%
    String ctype = request.getParameter("ctype");
    String del = request.getParameter("del");
    String cRegion = request.getParameter("cRegion");
    String[] countryregions = null;
    java.util.Vector filtercountry = null;
    if(cRegion!=null)
    {
    if(cRegion.equals("00"))
    {
    countryregions=request.getParameterValues("region");
    filtercountry = //retrieve countries from database according to regions
    }
    }

    if(del != null && ctype!= null)
    {
    if(!del.equals("00"))
    {
    if(ctype.equals("pp"))
    {
    int n = Integer.parseInt(del);
    String[] ppArray = //get country from Database
    java.util.Vector tempppArray = new java.util.Vector();
    for(int t=0;t<ppArray.length;t++)
    {
    if(t!=n)
    tempppArray.add(ppArray[t]);
    }
    String[] newppArray = new String[tempppArray.size()];
    for(int y=0;y<newppArray.length;y++)
    newppArray[y] = (String)tempppArray.get(y);
    //setting the countries into JavaBeans
    response.sendRedirect("addCountry.jsp");
    }
    else if(ctype.equals("mp"))
    {
    int n = Integer.parseInt(del);
    String[] mpArray = //get countries from Database
    java.util.Vector tempmpArray = new java.util.Vector();
    for(int t=0;t<mpArray.length;t++)
    {
    if(t!=n)
    tempmpArray.add(mpArray[t]);
    }
    String[] newmpArray = new String[tempmpArray.size()];
    for(int y=0;y<newmpArray.length;y++)
    newmpArray[y] = (String)tempmpArray.get(y);
    //add countries into JavaBeans
    response.sendRedirect("addCountry.jsp");
    }
    }
    }

    int countryregioncount = //get the size of the number of region in the database
    %>
    <%
    String add = request.getParameter("add");
    if(add != null)
    {
    if(add.equals("00"))
    {
    if(ctype!=null)
    {
    if(ctype.equals("pp"))
    {
    //setting countries in JavaBeans
    //returning to main page
    response.sendRedirect("addCountry.jsp");
    }
    else if(ctype.equals("mp"))
    {
    //setting countries in JavaBeans
    //returning to main page
    response.sendRedirect("addCountry.jsp");
    }
    }
    }
    }
    %>
    <html>
    <head>
    <title>Countries</title>
    <SCRIPT language="JavaScript">
    function validateforms(val)
    {
    // set var checkbox_choices to zero
    var checkbox_choices = 0;
    // Loop from zero to the one minus the number of checkbox button selections
    for (counter = 0; counter < document.countryregion.country.length; counter++)
    {
    // If a checkbox has been selected it will return true
    // (If not it will return false)
    if (document.countryregion.country[counter].checked)
    {
    checkbox_choices = checkbox_choices + 1;
    }
    }
    if (checkbox_choices < 1)
    {
    // If there were less then one selection made display an alert box
    alert("The following error(s) occurred: \n- Country is required.");
    return false;
    }
    else{
    // at least a checkbox is checked
    document.countryregion.action='presenceCountries.jsp?add=00&ctype'+val+'';
    document.countryregion.submit();
    }
    }
    function chkforms(val)
    {
    // set var checkbox_choices to zero
    var checkbox_choices = 0;
    // Loop from zero to the one minus the number of checkbox button selections
    for (counter = 0; counter < document.countryregion.region.length; counter++)
    {
    // If a checkbox has been selected it will return true
    // (If not it will return false)
    if (document.countryregion.region[counter].checked)
    {
    checkbox_choices = checkbox_choices + 1;
    }
    }
    if (checkbox_choices < 1)
    {
    // If there were less then one selection made display an alert box
    alert("The following error(s) occurred: \n- Country Region is required.");
    return false;
    }
    else{
    // at least a checkbox is checked
    document.countryregion.action='presenceCountries.jsp?cRegion=00&ctype='+val+'';
    document.countryregion.submit();
    }
    }
    function backpage(val)
    {
    document.countryregion.action='presenceCountries.jsp?del=00&ctype='+val+'';
    document.countryregion.submit();
    }
    </SCRIPT>
    </head>

    <body bgcolor="#FFFFFF">
    <form name="countryregion" action="" method="post">
    <%//for the country regions
    if(cRegion == null){%>
    <table border=0 align="center">
    <tr><td>
    <p><SPAN class=headerbig>Country Regions</SPAN></p>
    </td></tr><tr><td><br></td></tr>
    <%for(int i=0;i<countryregioncount; i++){%>
    <tr><td>
    <input type="checkbox" name="region" value="<%=proBean.getCountryRegionList(i)%>">
    <%=proBean.getCountryRegionList(i)%><br>
    </td></tr>
    <%}%>

    <tr><td align= center>
    <br><input type="button" name="Submit" value="Submit" class="formbutton" onClick="return chkforms('<%=ctype%>')">
    </td></tr>
    </table>
    <%}else{%>
    <h1>Countries</h1>
    <br>
    <table>
    <%for(int j=0;j<filtercountry.size();j++){%>
    <tr>
    <td>
    <input type="checkbox" name="country" value="<%=filtercountry.get(j)%>">
    <%=filtercountry.get(j)%>
    </td>
    </tr>
    <%}%>
    </table>
    <br>
    <input type="button" name="Back" value="Back" class="formbutton" onClick="return backpage('<%=ctype%>')">
    <input type="Submit" name="Submit" value="Submit" class="formbutton" onClick="return validateforms('<%=ctype%>')">
    <%}%>
    </form>
    </body>
    </html>

    Question 1: How to close the popup window using Java in JSP?

    Question 2: how to redirect the page to the main page after processing the info?

    Question 3: how to refresh the main page so that it will display the countries from JavaBeans after the popup window is closed?

    Thks a lot....
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Well, you have quite a lot of information you need. Despite the fact that this is a jsp, the only one that I can see that might actually be a java problem is #2.

    I am assuming you are asking how you redirect a user after they have submitted some data. If so, then you can use the pageContext.forward() method to forward to another page or servlet.

    Your other questions are actually html/javascript questions. I would suggest posting in those forums for those answers.

IMN logo majestic logo threadwatch logo seochat tools logo