• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 561
  • Last Modified:

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.)
0
99525
Asked:
99525
1 Solution
 
kotanCommented:
Yes, you can.That is a correct method.
If you want to disabled html contains. Try this,

<%
if (condition == true) {
%>
html things.
<%
}
%>


Is that what you want?
0
 
99525Author Commented:
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?
0
 
kotanCommented:
There is no way to do that.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
raid999Commented:
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");
  }
%>
0
 
pellepCommented:
you could simple do
<% if (condition == true) return; %>
which will cease execution of the servlet.
0
 
sushifishCommented:
try this

<%
if(cond==true){
response.sendRedirect("a.html");
}
else{
response.sendRedirect("b.html");
%>

Note: a.html is the page that display all your output.
      b.html is the empty page.

hope it helps.
0
 
99525Author Commented:
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now