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.

**Submit.jsp** 

```
<%
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());
            }
%>

```

---

Here is the decrypt.jsp , which decrypts the string . It gets the encrypted string from submit.jsp through `HttpUrlConnection`.

**Decrypt.jsp**

```
<script src="js/client.js"></script>

        <%
        String encyptPass=request.getParameter("encryptedPassword");

                %>

 <script type="text/javascript">

  var decryptStr = Aes.Ctr.decrypt('<%=encyptPass%>','',256);

document.writeln(decryptStr);

</script>

```