99525
asked on
How to stop the output in a .jsp file
Can I stop the following contents in a .jsp file when certain condition is met? Such as:
<%
if (condition == true)
Stop the output
%>
Following are the other contents in this page.
(These contents shouldn't be displayed if the condition = true.)
<%
if (condition == true)
Stop the output
%>
Following are the other contents in this page.
(These contents shouldn't be displayed if the condition = true.)
ASKER
This can end the output. But this is not what I want.
Because the "{" and the "}" are seperated by many comlicated Html mess. It's not very clear and easy to maintain.
Is there any usages in JSP like output.end or output.finish?
Because the "{" and the "}" are seperated by many comlicated Html mess. It's not very clear and easy to maintain.
Is there any usages in JSP like output.end or output.finish?
There is no way to do that.
I think it is do able
There are two ways to solve that:
1-
<%
if (condition==true){
%>
<input type="text"> or any HTML code
<%
}else{
%>
<HTML CODE>
<%
}
%>
2-
<%
PrintWriter out=response.getWriter();
if (conditon==true){
out.println("<HTML>");
}else{
out.println("any html code");
}
%>
There are two ways to solve that:
1-
<%
if (condition==true){
%>
<input type="text"> or any HTML code
<%
}else{
%>
<HTML CODE>
<%
}
%>
2-
<%
PrintWriter out=response.getWriter();
if (conditon==true){
out.println("<HTML>");
}else{
out.println("any html code");
}
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this
<%
if(cond==true){
response.sendRedirect("a.h tml");
}
else{
response.sendRedirect("b.h tml");
%>
Note: a.html is the page that display all your output.
b.html is the empty page.
hope it helps.
<%
if(cond==true){
response.sendRedirect("a.h
}
else{
response.sendRedirect("b.h
%>
Note: a.html is the page that display all your output.
b.html is the empty page.
hope it helps.
ASKER
pellep's comment is close to the solution what I want.
sushifish's comment also works. But sendRedirect is related to HTTP header. One should be careful if he uses this method.
return; will ignore remaining HTML tags, and makes them unmatch. I think current browsers can deal with this.
So I will accept pellep's answer.
Thank you.
sushifish's comment also works. But sendRedirect is related to HTTP header. One should be careful if he uses this method.
return; will ignore remaining HTML tags, and makes them unmatch. I think current browsers can deal with this.
So I will accept pellep's answer.
Thank you.
If you want to disabled html contains. Try this,
<%
if (condition == true) {
%>
html things.
<%
}
%>
Is that what you want?