0

I wanted to use a scriplet inside a java script function. I wanted to check for some attribute's vale and give an alert according to that. Following is the function in which the only scriplet statement gives an error.

function UploadMessage() {
   <% if((String)request.getAttribute("SuccessMessage").compareTo("Uploaded successfully") == 0) { %>
        alert("File Successfully uploaded !");
    <% 
     } %>
}

Is there any way i can do this ? What is the problem here ?

NOTE : I have placed the above snippet in a jsp page

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
  • possible duplicate of [How to use scriptlet inside javascript](http://stackoverflow.com/questions/5158400/how-to-use-scriptlet-inside-javascript) – mplungjan Apr 25 '12 at 06:02
  • @mplungjan I have placed the scriplet in jsp page. Now is it a duplicate ? – Suhail Gupta Apr 25 '12 at 06:04
  • The question I linked to is very similar to your question. In this case it was not the placing of the scriptlet but a syntax error you had an issue with. Still a good link for those who come after – mplungjan Apr 25 '12 at 07:21
  • In the future questions, please do not ignore/generalize errors as if they are useless garbage. They namely contain the answer. If you don't understand errors, post them in the question so that we can translate them in layman's terms. You know, once the error is *understood*, the solution is nothing more than obvious. So, do not say "I got errors", but copypaste them. – BalusC Apr 25 '12 at 15:49

1 Answers1

1
function UploadMessage() {
       <% if(((String)request.getAttribute("SuccessMessage")).equals("Uploaded successfully")) { %>
            alert("File Successfully uploaded !");
        <% 
         } %>
    }

Problem was -

  1. The method compareTo(String) is undefined for the type Object
  2. Incompatible operand types String and int
Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103