Solved

How to stop the output in a .jsp file

Posted on 2002-05-08
7
533 Views
Last Modified: 2012-05-05
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
Comment
Question by:99525
7 Comments
 
LVL 6

Expert Comment

by:kotan
ID: 6998100
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
 

Author Comment

by:99525
ID: 6998119
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
 
LVL 6

Expert Comment

by:kotan
ID: 6998134
There is no way to do that.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:raid999
ID: 6998511
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
 
LVL 4

Accepted Solution

by:
pellep earned 50 total points
ID: 6999089
you could simple do
<% if (condition == true) return; %>
which will cease execution of the servlet.
0
 

Expert Comment

by:sushifish
ID: 7000524
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
 

Author Comment

by:99525
ID: 7000538
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the hope of saving someone else's sanity... About a year ago we bought a Cisco 1921 router with two ADSL/VDSL EHWIC cards to load balance local network traffic over the two broadband lines we have, but we couldn't get the routing to work consi…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now