Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: issue with jsp code

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy issue with jsp code

    Hello Java Gurus,
    I'm attaching some sample code from my server. I'm basically getting some weird error from second block of my code below.
    The second block contains if/else; and having hard time to fix variable issue. I'm newbie, learning java.
    The first block and second block contains similar code except that second block contains if/else.
    I've to use if/else in second block to filter data with null value.
    How do I fix the if/else block? If I remove if/else block, the code works just fine.
    Your help is greatly appreciated.



    -----------------------first block works without issue----------------------------------------
    java.util.Date creationTime=userProperties.getDate("CREATE_TIME") ;
    String DATE_FORMAT="MM/dd/yyyy";
    SimpleDateFormat sdf=new SimpleDateFormat(DATE_FORMAT);
    out.println ("Creation Time : "+sdf.format(creationTime)+"<br>");


    --------------------second block if/else this one does not work-------------------------------
    if(userProperties.getProperty("LAST_LOGTIME") != null) /* This field contains date and null value*/
    {

    java.util.Date lastLoginTime=userProperties.getDate("LAST_LOGTIME ");
    String LAST_DATE="MM/dd/yyyy";
    SimpleDateFormat lastdatesdf=new SimpleDateFormat(LAST_DATE);
    out.println ("Creation Time : "+lastdatesdf.format(lastLoginTime)+"<br>");
    }
    else
    {
    lastLoginTime=" ";
    }

    ---------------------if/else creates this error block-----------------------
    lastLoginTime cannot be resolved to a variable
    73: }
    74: else
    75: {
    76: lastLoginTime=" ";
    77: }
    ----------------------------------------------------------------------------



    Thanks,
    Zulu


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,512
    My Mood
    Grumpy
    Thanks
    0
    Thanked 165 Times in 156 Posts

    Default Re: issue with jsp code

    The only possible way for the else branch to be executed is if getProperty returns null despite your assurances that it doesn't.
    System.out.println(userProperties.getProperty("LAST_LOGTIME"));
    Try adding that line directly before the if statement and see what output you get.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: issue with jsp code

    I put that code before the if statement but it did not return anything, it's blank. Anything else I could try?

    Thanks,

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: issue with jsp code

    That line should not "return" anything, it should print something to the console (or somewhere else visible depending on your environment), what is printed?
    Add some additional text to the line like a few numbers or special characters to make it easy to identify when the line is printed out.

    lastLoginTime=" "; is not a valid java.util.Date object

    lastLoginTime cannot be resolved to a variable because it was declared inside the block of code known as the if block, and the else block is not part of the if block. You will need to increase the scope of the variable to include its usage in the else block

Similar Threads

  1. Issue in a code
    By ayyappad in forum What's Wrong With My Code?
    Replies: 6
    Last Post: August 3rd, 2013, 07:17 PM
  2. Help needed - Embedding javascript code in JSP code.
    By chinnu in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: October 29th, 2012, 01:09 PM
  3. [SOLVED] Netbeans JSP issue
    By ek_swaim in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: June 12th, 2012, 08:48 PM
  4. I am having an issue with my code
    By gmamagoodwin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 9th, 2012, 10:36 PM
  5. Problem with my jsp code
    By ur2cdanger in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: October 16th, 2011, 01:12 AM