Solved

setting default values to a from field from a java calendar

Posted on 2003-11-04
6
232 Views
Last Modified: 2010-03-31
hi I have the below code.

1. I need to set the start and end date out of these code as the value for my form field.

as per this code, rightnow it's brining out the whole "java.util.GregorianCalendar[time=1068969600000,areFieldsSet=true, etc., etc., as the value.

what is wrong.

2. Also besides the default values the form fields should be able to accept user input values and pass them to a sql query.

3. how do you make a query out of these values to get data out of a MYSQL db, where it has the expires date along with other data.

<%

Calendar rightNow = Calendar.getInstance();
System.out.println("startdate" + rightNow) ;
// shift 2 weeks and back to Sunday
Calendar start = Calendar.getInstance();
start.add(Calendar.DATE, 14);
start.set(Calendar.HOUR, 0);
start.set(Calendar.MINUTE, 0);
start.set(Calendar.SECOND, 0);
start.set(Calendar.MILLISECOND, 0);
while(start.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
start.add(Calendar.DATE, -1);
}

// shift 2 weeks and up to Saturday (following Sundat midnight, actually)
Calendar end = Calendar.getInstance();

end.add(Calendar.DATE, 14);
end.set(Calendar.HOUR, 0);
end.set(Calendar.MINUTE, 0);
end.set(Calendar.SECOND, 0);
end.set(Calendar.MILLISECOND, 0);
while(end.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
end.add(Calendar.DATE, 1);
}

%>
<form action = ".jsp" method = "post">
Expires between
         <input type = 'text' name ='x' value='<%= start %>' > and
         <input type = text name =y value='<%= end %>'>
      <input type="BUTTON" value="Go" onclick="submit()">
      </form>
0
Comment
Question by:bobwilli
  • 2
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 84 total points
ID: 9681392
1. Because you're printing the whole Calendar:

System.out.println("startdate" + rightNow) ;

where you should (maybe) just print the date

System.out.println("startdate" + rightNow.getTime()) ;
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 84 total points
ID: 9681440
2. You can't use the String value of a Calendar for your form fields. You should probably use separate fields for day, month and year
3. Construct a Date using a SimpleDateFormat using the entered form fields and use that Date as input to a query
0
 
LVL 92

Assisted Solution

by:objects
objects earned 41 total points
ID: 9681639
Use DateFormat to format your date as required.

DataFormat df = new SimpleDateFormat(requiredformat);

%>
<form action = ".jsp" method = "post">
Expires between
        <input type = 'text' name ='x' value='<%= df.format(start.getTime()) %>' > and
        <input type = text name =y value='<%= df.format(end.getTime()) %>'>
     <input type="BUTTON" value="Go" onclick="submit()">
     </form>

0
 
LVL 92

Expert Comment

by:objects
ID: 11430895
formatting the input parameter value is a suitable (and desirable) solution to the problem.
The default Date format suggested by CEHJ is not really suitable for user input.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
why cannot we forward request once the response is committed 2 46
web services creation SOAP vs REST 5 57
ejb on wildfly 5 30
Chrome and Firefox Java 5 52
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

828 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