Error comparing java strings

0

I have the following situation.

I get a string that is in the ApplicationStorage location in a javascript variable.

<script>
    var sendForm = localStorage.getItem('f');
</script>

This same string I pass to a java variable to perform the necessary procedures that I will need.

<% 
    String id_formulario = "";
    id_formulario = "<script>document.write(sendForm)</script>"; 
%>

To perform tests I show this string with a

<%
    out.print(id_formulario);
%>

And that's okay! it is the exact string that was in the localStorage, however when I try to compare it with any string EQUAL the java does not recognize that they are equal and simply ignores.

<%
    if(id_formulario.equals("QUALQUERVALOR")){
        out.print("É igual!!!");
    }
%>

Why is this happening? I've tried everything and I can not solve this problem !!

    
asked by anonymous 21.12.2016 / 19:10

3 answers

0

JavaScript variables stay on the front end while the "<% code% >" are executed on the backend before sending the information.

One thing is you replicate data that is already by default added to javascript in your backend build, another is data that is in the "localStorage" of your client's browser.

After the request arrives at your "client", the codes "<%% >" no longer exist, since they have already been processed by your server.

In case your server when compiling did not have access to the localStorage:

<script> var sendForm = localStorage.getItem('f'); </script>

Failed to correctly process the rest of the code that needed this information.

    
21.12.2016 / 19:27
0

If what you said is correct.

  

But when I try to compare it with any string EQUAL, java does not recognize that they are equal and simply ignores

So the tool you are using is not compiling, or is trying in javascript thinking that it is equal to Java

    
21.12.2016 / 19:33
0

Problem solved,

The assignment I was making from a javascript variable to a jsp was wrong, the way it was written the java understood that the value of the serial variable literally "document.write (sendForm)". So I never serial like something I've been waiting for.

Solution,

Java does not work with localStorage, but it works with cookies, so I moved from localStorage to cookies and now it worked normally!

Thanks to all who responded, in the end it was just a search that returned me a wrong answer and caused so much trouble!

    
21.12.2016 / 19:49