Saturday, November 5, 2011

Passing variable values from one jsp to another jsp

Here is a very simple example to pass variable value from one jsp to another jsp.


Main JSP where variables are initialized.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title> Display</title>
    </head>

    <SCRIPT LANGUAGE="JavaScript">
        var no = 4;
        var eventName = new Array(no);


        eventName[3] = "E1";
        eventName[2] = "E2";
        eventName[1] = "E3";
        eventName[0] = "E4";
       
        function getDetails()
        {
            //window.location = "./Timeline - All.html";
            window.open('./child.jsp','','scrollbars=no,menubar=no,height=600,width=800,resizable=no,toolbar=no,location=no,status=no');
        } 
            
    </SCRIPT>

    <body>
        <h1>Hello!</h1>
        <form name ="f1" method="post">
            <table border="0" cellpadding="30">
                <tr>
                    <td>
                        <font size="3" face="arial" color="Black">Enter ID</font>
                    </td>
                    <td>
                        <input type="text" name="id">
                    </td>
                </tr>   

                <tr>
                    <td>
                        <input type="button" value="Submit" name="showId" onclick="getDetails()"/>
                    </td>
                </tr>

            </table>
        </form>

    </body>

</html>


Child JSP where we get the values of main jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Child</title>
    </head>

    <SCRIPT LANGUAGE="JavaScript">
        var no = 4;
        var eventName = window.opener.eventName;
       
       
        function getDetails()
        {
            for(i=0;i<no;i++) {
                alert(eventName[i]);
            }
        } 
            
    </SCRIPT>

    <body onload="getDetails()">

    </body>

</html>

6 comments:

Anonymous said...

Ӊey there! I hope you don't mind but Ӏ decided to
publish your web site: https://www.blogger.com/comment.g?postID=8182930401560880532&blogID=6488856944288748383 to my on-line directory.
I used, "Blogger: Java Source Codes and Everything" as your blog
titlе. I hope this is alright with yօu. In case
you'd liҟe me to change the title or remove
it completely, contact me at Ƅuϲkmаughan@gmail.com.
Thanks for your time.

Also visit my weƅ site taxes and Student loans

Anonymous said...

Greetings I am so excited I found your blog
page, I really found you by accident, while I was browsing on Bing for something else, Nonetheless I am here now and would just like
to say thanks a lot for a incredible post and a all round
enjoyable blog (I also love the theme/design), I don't have time to look over it all at the minute but I have saved it and also added in your RSS feeds, so when I have
time I will be back to read a lot more, Please do keep up the
excellent job.

my webpage - PUre Life Cleanse Review

Anonymous said...

Most are automatic, whipe some are semi-auto or burst fire.
Scavenger pro allows players to start with extra clips for there primary and secondary weapons.
Thee very first medal India received at the Olympic Games
came from Gagan Narang, a shooter who won the bronze medal, also known as the third prize, in the men's 10 m air rifle event.


Here is mmy blog: basketball ankle braces ()

Anonymous said...

Hi, i think that i saw you visited my site thus i came to “return the favor”.I am
trying to find things to enhance my website!I suppose
its ok to use some of your ideas!!

my weblog ... best muscle building supplements

Anonymous said...

Hello, yup this piece of writing is in fact pleasant and I have learned lot of things from it regarding blogging.
thanks.

Feel free to visit my page; pure garcinia cambogia in stores

Anonymous said...

You made some decent points there. I looked on the web for additional information about
the issue and found most people will go along with your views on this site.


For an incredible solution please visit this page: jennifer hudson weight loss

Total Pageviews