aspose file tools*
The moose likes JSP and the fly likes How Stop code execution in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How Stop code execution in JSP" Watch "How Stop code execution in JSP" New topic
Author

How Stop code execution in JSP

sohail khan
Greenhorn

Joined: May 18, 2004
Posts: 9
hi all,
i would like to know how to stop code execution in JSP.
In coldfusion we use cfabort tag

http://livedocs.macromedia.com/coldfusion/5.0/CFML_Reference/Tags3.htm

so what will be the equalent to cfabort in JSP.

Is it <jsp:forward page="Login.jsp"/>?


Advance thanks.web page
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Not understood the problem exactly. If you are talking about skipping the page then you can do it in JSP Taglib by using the Tag.SKIP_PAGE attribute.
It will skip the page for a specific condition that you will specify.
sohail khan
Greenhorn

Joined: May 18, 2004
Posts: 9
hi Ali Gohar ,


I dont want to skip the page.i just want to stop the process of the jsp page.

I use cfabort tag in coldfusion.
check the link below for more info abt the tag.

http://livedocs.macromedia.com/coldfusion/5.0/CFML_Reference/Tags3.htm


Like cfabort tag i want to know which command will stop the process of a jsp page.?
web page


waiting for expert solution....

Thanks a million.
Syed Saifuddin
Ranch Hand

Joined: Sep 01, 2003
Posts: 130
To stop the execution of thr page in the middle use javascript.
But this method does not stop exeution only stop displaying the rest of the generated page which is produce through execution.

To do this one more way is to use jsp:include page
In this method you have to devide your work in two part. First page only contain the code after which u want to stop the execution. and use jsp:include page tag where u want to include the rest of the processing in your page.

Second page contain the rest of the code which u want to resume after some condition.


Thank You & Best Regards,

Syed Saifuddin,
Senior Software Engineer

SAP Oracle AIX & Java Training
http://www.socialinet.com
sohail khan
Greenhorn

Joined: May 18, 2004
Posts: 9
hi saif,
i dont want to use javascript.
And i dont feel the second comment will work out for me.Any other solution?
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572


As i have understood from the example page you had told to see is that you want to stop the execution of a loop. You can use break condition in a loop to come out from the loop or to stop the execution of loop you can say.

for(int i=0;i<4;i++){
if(i==2)
break;
//otherwise do the processing here
}

Is this your problem? if not then describe.
sohail khan
Greenhorn

Joined: May 18, 2004
Posts: 9
hi ali,
here is my code.


What i am trying to achieve with the above code is if u_name equals guest i just want to abort my jsp page and redirect to login.jsp and i dont want to continue the process(means i dont want to execute the sql staments if u_name is guest).
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
you can do it using response.sendRedirect("/login.jsp"). In this case a new request object will be created.

if(U_Name.equals("guest")){
response.sendRedirect("/login.jsp");
}else{
//do the process
}
and if you want the same request and response objects in login page then use <jsp:forward page="/login.jsp"/>
sohail khan
Greenhorn

Joined: May 18, 2004
Posts: 9
hi ali,
Is repsonse.sendRedirect will stop the process?i think it just forward to the login.jsp page.

if(U_Name.equals("guest")){
response.sendRedirect("/login.jsp");
}

if you go through my code again

if its a guest user i should display some html text and one anchor link when click on the link it should go to the login page?
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Ok sorry i didn't see that href. So you can do it as

if(U_Name.equals("guest")){
//here display message and href
}else{
//here do the processing of DB
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Stop code execution in JSP