wood burning stoves 2.0*
The moose likes JSP and the fly likes Need to fire an alert in jsp which is in middle of java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Need to fire an alert in jsp which is in middle of java code" Watch "Need to fire an alert in jsp which is in middle of java code" New topic
Author

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

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

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 )



Save India From Corruption - Anna Hazare.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Try using brackets in the scriptlet.



Generally, try not to use scriptlets in a JSP, these are for presentation only.


JDBCSupport - An easy to use, light-weight JDBC framework -
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you very much . I will try this .
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

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

Joined: Feb 22, 2005
Posts: 261
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

Joined: Apr 18, 2009
Posts: 2234

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

Joined: Feb 22, 2005
Posts: 261
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

Joined: Apr 18, 2009
Posts: 2234

Thank you very much Anirvan Majumdar .






 
GeeCON Prague 2014
 
subject: Need to fire an alert in jsp which is in middle of java code