aspose file tools*
The moose likes Servlets and the fly likes which one is a good Practice? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "which one is a good Practice?" Watch "which one is a good Practice?" New topic
Author

which one is a good Practice?

Ranjith R
Greenhorn

Joined: Sep 18, 2001
Posts: 22
Howdy ...reader..
this topic is rather about Style or Practice in JSP: Plz read the piece of codes below.
Style1
------
...
<h3>Agent name is :</h3>
<%
  if(agentCode.equals("007")){
   out.println("<b>James Bond</b>");
  }
  else{
   out.println("<b>Jennifer Lopez</b>");
  }
%>
Style2
------
<h3>Agent Name is:</h3>
<%  if(agentCode.equals("007")){
%>
<b>James Bond</b>
<%  }
  else{
%>
<b>Hanibal Lector</b>
<%
  }
%>
... uh...

SO... what do you say? ..

------------------
Take care
r@njith


Take care<BR>r@njith
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Personally: always the second one.
Additionally, the bold tags are common so I'd pull them out as well (separate content and mark-up)

Dave.
Shama Khan
Ranch Hand

Joined: Aug 14, 2000
Posts: 185
Agreed. I'd say the second one is more correct.

Shama
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
what about:
<h3>Agent name is :</h3>
<%
String strOut;
if(agentCode.equals("007")){
strOut = "<b>James Bond</b>";
}
else
{
strOut = "<b>Jennifer Lopez</b>";
}
out.println(strOut);
%>

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Syam Veerakumar
Ranch Hand

Joined: Sep 20, 2001
Posts: 49
Adam Hardy's type of code is always good Practice I guess.

A Quitter Never Wins<br />A Winner Never Quits
Ranjith R
Greenhorn

Joined: Sep 18, 2001
Posts: 22
..err...
but tell me is it considered as a bad practice if i am using more out.println(someThing) s? rather than stuff like <%=someThing %>
thankx
[This message has been edited by Ranjith R (edited October 12, 2001).]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"Ranjith R",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements.
Thanks.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: which one is a good Practice?