Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My date is not displaying on my form 1

Status
Not open for further replies.

CdnRebel

Programmer
Apr 5, 2003
39
0
0
CA
I have two tables in my form. One for the user input and one for the submit and exit buttons. In between I have javascript to output a date to the screen. It's not happening. What am I doing wrong? Here's the code:
<table>
<!-- data entry code goes here -->
</table>

<%
/** get today's date and save it in the today variable **/

Calendar cal = Calendar.getInstance();
Date today = new Date();
today = cal.getTime();

/** format the date for today variable and put it in the string variable DATE **/

SimpleDateFormat sdf= new SimpleDateFormat(&quot;EEEE, MMMM d, yyyy&quot;);

String DATE;

DATE=sdf.format(today);

out.println('&quot; + DATE +&quot;');
%>

<table align=&quot;center&quot;>
<!-- submit, exit, reset buttons -->
</table>
I know the date retrieval works. Does it only display outside a form? Is there a way to get it to display between the input and the buttons?
 
I'm assuming your using JSP (Java Server Pages). I wouldn't recommend using a variable called &quot;DATE&quot;, since this is the same name (ok - different case) as an object name (Date today = new Date()).

Try using a different name.

With this said, I think your problem is around the use of the &quot;quotes&quot; within your out.println statement. You are opening them with a single quote (') and appending a double quote (&quot;) for the string to be wrapped in, but you haven't closed your single quote(') before the string addition (+).

Try:
Code:
[b]out.println('&quot;' + DATE + '&quot;');[/b]

Pete.


Web Developer / Aptrix CMS (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Yes, I am using jsp and the javascript was working without the quotes and plus signs, but my other code that was working without the quotes and plus signs requires them now. So it would seem that something about the javascript environment has changed. I've tried the code with different combinations of single quotes, double quotes and plus signs. The problem still eludes me.

Mary
 
Mary,

Are you sure that you are running this code via a JSP Server!? You can run the code without the server, but you may end up with results as you are describing, because the browser doesn't understand the &quot;server-side&quot; commands.

Try using something like:
Code:
[URL unfurl="true"]http://127.0.0.1/thefile.jsp[/URL]

Pete.


Web Developer / Aptrix CMS (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
I think you still need to change the DATE part though... looking at the code again you need to use:
Code:
out.println(&quot;'&quot; + DATE +&quot;'&quot;);

Pete.


Web Developer / Aptrix CMS (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Yes, I have tried it with out.println(&quot;'&quot; + DATE + &quot;'&quot;) and I have tried using a different name and the results are the same. I don't know, if we have a JSP server here, but they should have one at school. I will try there tomorrow.
 
Pete,

You were right about needing the JSP server. Also, I did need to redefine my date with an explicit java constructor.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top