title: Pass parameter from javascript to JSP
body: <p>My form gets submitted on submit.jsp with an encrypted String, I decrypt it in javascript and want the decrypted string back in jsp from javascript.</p>
  
  <p><strong>Submit.jsp</strong>    </p>
  
  <pre><code>&lt;%
  try{
  
  String str=request.getParameter("password2");
  
  out.println("" +str);
  
  String decPass="";
  
  String res="";
  
  String url_name="http://localhost:8086/date/decrypt.jsp";
  
   String charset="UTF-8";
  
  String query=String.format("encryptedPassword=%s", 
  
  URLEncoder.encode(str,charset));
  
  URL url =  new URL(url_name+"?"+query);
  
  URLConnection con = url.openConnection();
  
   HttpURLConnection httpConnection = (HttpURLConnection)con;
  
   httpConnection.setRequestMethod("POST");
  
   httpConnection.setDoInput(true);
  
   httpConnection.setDoOutput(true);
  
   httpConnection.setRequestProperty("Accept-Charset",charset);
  
   httpConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset="+charset);
  
   httpConnection.connect();
  
   OutputStreamWriter wr  = new    OutputStreamWriter(httpConnection.getOutputStream());
  
   wr.write("query : "+query);
  
  
  if(httpConnection.getResponseCode()== HttpURLConnection.HTTP_OK )
  
   {
       String responseMessage = httpConnection.getResponseMessage();
       System.out.println(responseMessage);
  
       InputStream in = httpConnection.getInputStream();
  
       BufferedInputStream bufferReader = new BufferedInputStream(in);
       //res=kw.streamToString(in);
       //System.out.println(res);
       BufferedReader br = new BufferedReader(new InputStreamReader(bufferReader));
  
     while((decPass=br.readLine())!=null)
         {
         out.println(decPass);
         String dec = decPass;
          System.out.println(dec);
         }
    }
    wr.close();
   }
          catch(MalformedURLException me)
           {
              System.out.println("Error Message : "+me.getMessage());
  }
          catch(IOException e)
                  {
              System.out.println("Error Message : "+ e.getMessage());
              }
  %&gt;
  </code></pre>
  
  <hr>
  
  <p>Here is the decrypt.jsp , which decrypts the string . It gets the encrypted string from submit.jsp through <code>HttpUrlConnection</code>.</p>
  
  <p><strong>Decrypt.jsp</strong></p>
  
  <pre><code>&lt;script src="js/client.js"&gt;&lt;/script&gt;
  
          &lt;%
          String encyptPass=request.getParameter("encryptedPassword");
  
                  %&gt;
  
   &lt;script type="text/javascript"&gt;
  
    var decryptStr = Aes.Ctr.decrypt('&lt;%=encyptPass%&gt;','',256);
  
  document.writeln(decryptStr);
  
  
  &lt;/script&gt;
  </code></pre>