0

hi i have a javascript method which is reading byte array from applet class i want to put that byte array into request scope to pass the controller class. for that i created one hidden filed and here my doubt is how can i pass that byte array from java script method to hidden field can any body give the solution.

here is my jsp class.

<html>
    <body>
        <script type="text/javascript">
        var a="image";
        function printIt(){
            a=document.getElementById('string').value;
        }
        </script>

        <form name="formName" action="second.jsp">
            <input type="hidden" value='a' name="name" id="string"/>
            <input type="submit" id="abcId" name="abcName" onsubmit="printIt()"
                    value="submit"/>
        </form>
    </body>
</html>
Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99
Sthogari
  • 45
  • 2
  • 14

3 Answers3

1

Here you can try to use jquery code to achieve this :

<script type="text/javascript">
 $('#abcId').on('click', function()
 {

     var a="image";
     $('#string').val(a); //<-- this code will take a variable as value an assign it into hidden input

     $('#formID').submit();

 }
</script>

HTML code

<form name="formName" action="second.jsp" id="formID">
  <input type="hidden" value='a' name="name" id="string"/>
  <input type="submit" id="abcId" name="abcName" value="submit"/>
</form>
Norlihazmey Ghazali
  • 9,000
  • 1
  • 23
  • 40
0

With jquery

you want to get the value of your hidden field and set it with return value of the function that is getting the byte array like

$("#string").val(functionThatReturnTheByteArray())

then you want to submit the form with the hidden field

$("form[name='formName']").submit()

this will submit the form with the hidden field containing your byte array.

Summary

$("#string").val(functionThatReturnTheByteArray())
$("form[name='formName']").submit()
william.eyidi
  • 2,315
  • 4
  • 27
  • 39
0

I think you will need to string-encode your byte-array in order to be able to send it using the request. This might help here: Convert array of byte values to base64 encoded string and break long lines. Afterwards you can assign it using

document.getElementById('string').value = encode(yourData);

Hope that helps.

Community
  • 1
  • 1
Patrik
  • 1,355
  • 12
  • 22