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

4
  • possible duplicate of How to use scriptlet inside javascript Commented Apr 25, 2012 at 6:02
  • @mplungjan I have placed the scriplet in jsp page. Now is it a duplicate ? Commented Apr 25, 2012 at 6: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 Commented Apr 25, 2012 at 7: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. Commented Apr 25, 2012 at 15:49

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

but the method compareTo(String) is undefined for the type Object yrr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.