•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 391,965 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,129 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 440 | Replies: 2
![]() |
•
•
Join Date: Jan 2008
Posts: 12
Reputation:
Rep Power: 1
Solved Threads: 0
i don't know how to discuss it clearly but i'll try.. my problem is when my index page loads, the current value of my variable year is null.. so it displays the word null.. ahm, only if i click the submit button that's the time that a value is inserted in that variable.. i have values on my select tag.. from 2008 - 2007.. that's where data should come from..
so when i get parameter from the select tag, once it initially loads, null value is generated.. hope it's a li'l bit clearer.. i'm just a newbie.. that's why..
<html>
<head>
<title></title>
</head>
<body>
<%
java.util.Date today = new java.util.Date();
String s = DateFormat.getDateInstance(DateFormat.LONG).format(today);
out.print(s);
%>
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td>
<form method = "post" action = "MonthlyTrend.jsp">
<select name = xyear>
<%
String year = request.getParameter("xyear");
for (int i=(1900 + today.getYear()); i >= 2005; i--) {
if(i == today.getYear())
out.println("<option value=" + i + " selected = \"selected\">" + i + "</option>"+i);
else
out.println("<option value=" + i + ">" + i + "</option>"+i);
}
%>
</select>
<input type = "Submit" value = "GO">
</form>
</td>
</tr>
</table>
<br><b><%= year %> Monthly Test MCBJ Trend</b></font><br>
</body>
</html>
so when i get parameter from the select tag, once it initially loads, null value is generated.. hope it's a li'l bit clearer.. i'm just a newbie.. that's why..
<html>
<head>
<title></title>
</head>
<body>
<%
java.util.Date today = new java.util.Date();
String s = DateFormat.getDateInstance(DateFormat.LONG).format(today);
out.print(s);
%>
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td>
<form method = "post" action = "MonthlyTrend.jsp">
<select name = xyear>
<%
String year = request.getParameter("xyear");
for (int i=(1900 + today.getYear()); i >= 2005; i--) {
if(i == today.getYear())
out.println("<option value=" + i + " selected = \"selected\">" + i + "</option>"+i);
else
out.println("<option value=" + i + ">" + i + "</option>"+i);
}
%>
</select>
<input type = "Submit" value = "GO">
</form>
</td>
</tr>
</table>
<br><b><%= year %> Monthly Test MCBJ Trend</b></font><br>
</body>
</html>
Change
to
But you also really need to change "today" to be Calendar and use get(Calendar.YEAR) instead of getYear(), as the getYear() method of Date is deprecated for a reason. See the API for Calendar.
Edit: Also, you really should not be using scriptlets in a JSP. What you're doing here can be handled by a simple bean and a couple of standard JSTL tags.
String year = request.getParameter("xyear");String year = request.getParameter("xyear");
if (year == null) {
year = today.getYear();
} But you also really need to change "today" to be Calendar and use get(Calendar.YEAR) instead of getYear(), as the getYear() method of Date is deprecated for a reason. See the API for Calendar.
Edit: Also, you really should not be using scriptlets in a JSP. What you're doing here can be handled by a simple bean and a couple of standard JSTL tags.
Last edited by masijade : Jan 31st, 2008 at 5:59 am. Reason: Additional Info
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jan 2008
Posts: 32
Reputation:
Rep Power: 1
Solved Threads: 4
Change the code in red with the following.
Change to:
Java does not know where to find DateFormat. It is not in the default lang namespace but in java.text namespace.
I have run your code in my editor. I failed when i run it with your code, but worked when i run
it with my code.
java.util.Date today = new java.util.Date();
String s = DateFormat.getDateInstance(DateFormat.LONG).format(today);Change to:
String s = java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG).format(today);Java does not know where to find DateFormat. It is not in the default lang namespace but in java.text namespace.
I have run your code in my editor. I failed when i run it with your code, but worked when i run
it with my code.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
Other Threads in the JSP Forum
- Previous Thread: Error while retreiving Integer value from database
- Next Thread: send session variable in an array



Linear Mode