IF statement, filling in the blanks

I have the following section of code, but I only want to display the Telephone Number when there is a telephone number.

This is a JSP page, how would I go about doing this? I know how to do it in ASP, but not JSP. I was basically looking for an IF statement, if telephone number exists, then output the following code...

Customer Name = <em><%=request.getParameter("cust_firstname") + " " + request.getParameter("cust_surname")%></em><br>
Telephone Number = <em><%=request.getParameter("cust_phone_intl") + " " +
                          request.getParameter("cust_phone_area") + " " +
                          request.getParameter("cust_phone_number")%></em><br>
Email Address = <em><%=request.getParameter("cust_email")%></em><br>
Query = <em><%=request.getParameter("trans_objective")%></em><br>
Callback Time = <em><%=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.SHORT).format( ((Calendar)session.getAttribute("cust_callback_datetime")).getTime() )%></em><br>
LVL 6
PhilAIAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
<%
    if( request.getParameter("cust_phone_intl") != null &&
        request.getParameter("cust_phone_area") != null &&
        request.getParameter("cust_phone_number") != null )
    {
%>
Customer Name = <em><%=request.getParameter("cust_firstname") + " " + request.getParameter("cust_surname")%></em><br>
Telephone Number = <em><%=request.getParameter("cust_phone_intl") + " " +
                          request.getParameter("cust_phone_area") + " " +
                          request.getParameter("cust_phone_number")%></em><br>
Email Address = <em><%=request.getParameter("cust_email")%></em><br>
Query = <em><%=request.getParameter("trans_objective")%></em><br>
Callback Time = <em><%=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.SHORT).format( ((Calendar)session.getAttribute("cust_callback_datetime")).getTime() )%></em><br>
<%
    } // end of if statement
%>
0
PhilAIAuthor Commented:
Am I missing something?

It is printing all of that text on the page whether request.getParameter("cust_phone_intl") is null or not.
I even tried request.getParameter("cust_phone_intl") != ""
0
PhilAIAuthor Commented:
By the way, I only need to check the request.getParameter("cust_phone_intl") parameter, so changed it to read:

<%
    if( request.getParameter("cust_phone_intl") != null )
    {
%>
Customer Name = <em><%=request.getParameter("cust_firstname") + " " + request.getParameter("cust_surname")%></em><br>
Telephone Number = <em><%=request.getParameter("cust_phone_intl") + " " +
                          request.getParameter("cust_phone_area") + " " +
                          request.getParameter("cust_phone_number")%></em><br>
Email Address = <em><%=request.getParameter("cust_email")%></em><br>
Query = <em><%=request.getParameter("trans_objective")%></em><br>
Callback Time = <em><%=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.SHORT).format( ((Calendar)session.getAttribute("cust_callback_datetime")).getTime() )%></em><br>
<%
    } // end of if statement
%>
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

TimYatesCommented:
cool :-)  That should work :-)
0
PhilAIAuthor Commented:
It doesn't, it stills outputs all the text to the page...
0
PhilAIAuthor Commented:
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page errorPage="InteractError.jsp" %>
<%@ page import="java.text.DateFormat" %>
<%@ page contentType="text/html; charset=ISO-8859-1" %>
<%@ page buffer="8kb" %>
<%@ page info="InteractConfirm" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">

<html>
<head>
      <title>Interaction</title>
      <link href="/Brands/PC/css/styles.css" rel="stylesheet" type="text/css">
      <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">

<script language = "JavaScript">
<!--
// Use this function to create a cookie
function setCookie(name, value, expires)
{
  document.cookie = name + "=" + escape(value) + ";path=/" +
  ((expires == null) ? "" : ";expires=" + expires.toGMTString());
}

// Use this function to retrieve a cookie
function getCookie(name)
{
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0)
  {
    var begin = dc.indexOf(cname);
    if (begin != -1)
    {
      begin += cname.length;
      var end = dc.indexOf(";", begin);
      if (end == -1)
        end = dc.length;
      return unescape(dc.substring(begin, end));
    }
  }
  return null;
}

function isCookieEnable()
{
   // check which browser is used (netscripe or IE)
   var myBrowser = navigator.appName.substr(0,3);
   if (myBrowser == "Net")
   {
      // This is a Netscape browser
      var cookieName = "_SWCP_CookieCheck";
      var cookieValue = "checkCookie";
      setCookie(cookieName, cookieValue);
      // Check to see if able to create cookie
      var myCookie = getCookie(cookieName);
      if (myCookie == null)
         return false;
      else
        return true;
    }
    else
    {
       // This is a IE
       if (navigator.cookieEnabled)
          return true;
       else
          return false;
    }
}

function custLogOn()
{
    if (isCookieEnable())
    {
       // Create a cookie name _SWRS_StartPage and expired in an hour.
       var exp = new Date();
       exp.setTime(exp.getTime() + (60*60*1000));
       var cookieName = "_SWCP_StartPage";
       var cookieValue = window.location.href;
       setCookie(cookieName, cookieValue, exp);
       window.location = "financial/login.html";
    }
    else
    {
       // Cookies not enabled on browser
       alert("This page requires browser cookies to be enabled.\n Please enable browser cookies and come back again!");
    }
}

// -->
</script>

</head>

<%
//need to set the encoding of the incoming request to utf-8 because
//JRUN defaults to Latin-1 even though the client side web
//page might be encoded in utf-8
request.setCharacterEncoding("utf-8");
%>

<body background="/Brands/PC/images/motortop.gif" leftmargin="0" topmargin="100" marginwidth="25" marginheight="0">

<h2><center>Your Transaction Number is <%=(String)session.getAttribute("trans_id")%></center></h2>
<hr>
<p><b><I>Note</I> : For your own records here is the information you have just sent to us.<br>
<ul>
Customer Name = <em><%=request.getParameter("cust_firstname") + " " + request.getParameter("cust_surname")%></em><br>
<%
    if (request.getParameter("cust_phone_intl") != "")
    {
%>
Telephone Number = <em><%=request.getParameter("cust_phone_intl") + "! " +
                          request.getParameter("cust_phone_area") + " " +
                          request.getParameter("cust_phone_number")%></em><br>
<%
    }
%>
Email Address = <em><%=request.getParameter("cust_email")%></em><br>
Query = <em><%=request.getParameter("trans_objective")%></em><br>
<!--
Callback Time = <em><%=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.SHORT).format( ((Calendar)session.getAttribute("cust_callback_datetime")).getTime() )%></em><br>
-->

</b></ul>

<table align="center">
  <tr>
    <td><a href="javascript:window.close();">Close Window</a></td>
  </tr>
</table>

</body>
</html>
0
TimYatesCommented:
why have you put

    if (request.getParameter("cust_phone_intl") != "")

instead of

    if (request.getParameter("cust_phone_intl") != null)

?
0
PhilAIAuthor Commented:
Null was not working, so I thought I'd try ""
0
TimYatesCommented:
Strange...  if no value is being sent through to this page then null should work...

Try:

    if( request.getParameter("cust_phone_intl") != null && request.getParameter("cust_phone_intl").length() > 0 )
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TimYatesCommented:
oh, and just so you know, you can't compare strings like

    if (request.getParameter("cust_phone_intl") != "")

that will always return true as != will compare the String objects, not their contents...

The better way of doing that is:

    if ( !request.getParameter("cust_phone_intl").equals( "" ) )

Buf of course, if it is null, that will throw an exception...
0
TimYatesCommented:
Cool :-)

Glad I could help :-)

To make it look a bit neater, you can use a String variable to hold the value...

Customer Name = <em><%=request.getParameter("cust_firstname") + " " + request.getParameter("cust_surname")%></em><br>
<%
    String intl = request.getParameter("cust_phone_intl") ;
    if( intl != null )
        intl = intl.trim() ; // get rid of any spaces
    if( intl != null && intl.length() > 0 )
    {
%>
Telephone Number = <em><%=request.getParameter("cust_phone_intl") + "! " +
                          request.getParameter("cust_phone_area") + " " +
                          request.getParameter("cust_phone_number")%></em><br>
<%
    }
%>
Email Address = <em><%=request.getParameter("cust_email")%></em><br>
Query = <em><%=request.getParameter("trans_objective")%></em><br>

Good luck with it!!

Tim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.