Solved

How to stop the output in a .jsp file

Posted on 2002-05-08
7
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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!

 
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

Industry Leaders: 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!

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

690 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