• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to fire an alert in jsp which is in middle of java code

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I have a jsp which also contains some java code inside it .

The java code inside the jsp does some operations like searching .

Now my requirement is that how can i put an alert inside the java scriptlets



PLease help how can i do this

( I tried this way but this script got executes as soon as this jsp page is called )

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using brackets in the scriptlet.



Generally, try not to use scriptlets in a JSP, these are for presentation only.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much . I will try this .
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry to say this did not worked .

I tried the way as you suggested

else if(action.equals("blowup"))
{
%>

<script>
document.getobj.action="Blowup.jsp";
document.getobj.submit();
</script>

<%
}


 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fear that you're not clear about the lifecycle of a JSP. All your Java code within the <% ... %> gets executed at the server itself. If you're hoping that an alert message will be displayed to the client while the server is executing the Java scriplet then you're completely mistaken.
You need to capture the scenario of displaying an alert in a request attribute and pass it to the JSP, where you can check on the value and display the alert accordingly.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to capture the scenario of displaying an alert in a request attribute and pass it to the JSP.


Thank you very much .Seems valuable ,In my scenario how can i achive this .


else if(action.equals("blowup"))
{

// Setting some parameters in request scope here to send it to the other page

}


Please tell me
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before you forward the control to the JSP, in your servlet [or whatever handler class you've got], put in the following -
In your JSP you can then check on this attribute value and alert the user this way -
That should do it. But I hope that you've gone through the JSP lifecycle text and understand the mistake you were making.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Anirvan Majumdar .






 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic