Solved

How to stop the output in a .jsp file

Posted on 2002-05-08
7
531 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

17 Experts available now in Live!

Get 1:1 Help Now