简体   繁体   中英

How to pass values from external page to parent page in JSP

I have a problem that I wanted to solve for my client. i hope that I will explain it well. let say that I have a JSP form with some fields of personal data and on same page is popoup button that opens another page with form that have fields for personal address to add in parent form page. The problem is that popup form came from external URL. How can I submit addres from child page to parent page?

Thank you in advance.

here is example what I ment

MyForm - Parent form page:

<html>
    <body>
        <input id="name" value ="John Smith" />

        <input id="billingCity" value=""/>
        ...

    </body>
 </html>

Address verifcation page:

<html>
    <body>

    <form action ="https://foo.com/HandleAddressValidationResults.jsp">
        <input id="city" value="Oregon" />

        ...
        <input type="submit" value="Accept" />
    </form>
    </body>
</html>

This scenario is easily solved using JavaScript. window.showModalDialog() method

If you click the link below you will understand easily.

Using Modal Window

For Example,

function openwindow()
{
    retval=window.showModalDialog("modaltarget.htm")
    document.getElementById('text1').value=retval
}

in your parent page , when you call the child pop up page suppose parent page is parent.jsp and in the pop you are calling child.jsp in your parent jsp , when you call the child page

window.location = ../child.jsp

pass some parameters

<script>
var value1 = document.getElementByID('name').innerHTML;
var value2 = document.getElementByID('billingCity').innerHTML;
window.location = "../child.jsp?param1="+value1+"&param2="+value2;
</script>

now these paraeters will be passed as request parameters in your child.jsp pop up page get values of param1,param2 ... and so on using request.getParameter() and set the values in input fields in child.jsp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM