Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to stop the execuation of jsp flow

 
Parshuram Walunjkar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%
boolean flag ;
// Some java execution and set the value of boolean variable
flag = true;
if(flag)
{
%>
<script>
alert(" Here I want to stop");
history.back()
</script>
<%
}
// Some java code to be execrated
//
//
//////

System.out.println(" some printing statement ");


%>
This is my sample jsp code.
If the variable flag is true then I want the alert message and execution to be stopped.
But actually this is not occurred. First the SOP will print and then at lastly the alert will occur.
Why this happens.?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks to me like the entire JSP executes and sends a page, no matter what the flag is. Why not finish off the page and execute return if the flag is true.
Bill
 
Nicolas Brasseur
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should first consider how JSP pages are treated by the web container (parsed, translated into a java servlet source file, compiled, instanciated, ...).
you should also consider that you are mixing JSP tags (that will become java code executed on the server) with Javascript code (that will be executed on the client-side) ...
Whatever ... looking at your code I think adding a return should solve your problem ...


Nicolas
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic