Results 1 to 3 of 3
  1. #1
    kader_sit is offline Member
    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Default how to pass parameter from one jsp to another jsp

    how pass parameter from one jsp to another jsp using button onclick??

    i use this one..
    onclick="location.href='http://localhost:8080/sampleajax/getpass.jsp"

    in the above how can i pass parameter???

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    in this case, i assume that this is on a different page than the getpass.jsp and we want to on click make it go to to this getpass.jsp.

    for an onClick() event handler, this is entirely a client-side javascript operation here. that is to say, this is not JSP specific.

    perhaps you could use a HTML <form> with a hidden field(s) that you would stuff full of the parameters you would want to send to the second page. And then, have the onClick() post this form, instead of adjusting the location.href.

    For example.

    Java Code:
    <form name="submitToGetPassForm" action="getpass.jsp">
      <input type="hidden" name="param1" value="someValue"/>
      <input type="hidden" name="param2" value=""/>
    </form>
    
    <script type="text/javascript">
      function doGetpass() {
        var form = document.forms['submitToGetPassForm'];
        // stuff some value into the form field
       form.elements['param2'].value='myothervalue';
       form.submit();
     }
    </script>
    <span onClick="doGetpass();">Bla bla bla</span>
    You could also have the option of making this be a POST or GET style request.

    Note its been a while since i've had to do JavaScript, so this is probably terrible coding:).

  3. #3
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    This is how I do my passing,
    var Customer Number = 273;

    the param CN for Customer Number

    onclick="location.href='http://localhost:8080/sampleajax/getpass.jsp?CN=273";

    or put it in a variable

    onclick="location.href='http://localhost:8080/sampleajax/getpass.jsp?CN="+CustomerNumber+""

    than it will get carried to the next page where you will put this function at the top of your page,

    Java Code:
    function gup( name ){  
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
    var regexS = "[\\?&]"+name+"=([^&#]*)";  
    var regex = new RegExp( regexS ); 
     var results = regex.exec( window.location.href );  
    if( results == null )    return "";  
    else    return results[1];};
    than

    var newpageCustomerNumber = gup ( 'CN' );

    to get the variable
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

Similar Threads

  1. Replies: 2
    Last Post: 09-29-2009, 03:33 PM
  2. I can't seem to pass a file through a parameter
    By daletron3030 in forum New To Java
    Replies: 5
    Last Post: 01-15-2009, 06:07 AM
  3. Can a method take itself as parameter?
    By bukake in forum New To Java
    Replies: 10
    Last Post: 09-06-2008, 09:26 PM
  4. Replies: 1
    Last Post: 08-22-2008, 06:28 PM
  5. How to pass two parameter in struts-config using dynaActionForm
    By 82rathi.angara in forum Web Frameworks
    Replies: 2
    Last Post: 06-10-2008, 02:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •