User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jan 2008
Posts: 12
Reputation: wolverine_ramir is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
wolverine_ramir wolverine_ramir is offline Offline
Newbie Poster

Help need some help.. thanks..

  #1  
Jan 31st, 2008
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>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,360
Reputation: masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough masijade is a jewel in the rough 
Rep Power: 8
Solved Threads: 117
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: need some help.. thanks..

  #2  
Jan 31st, 2008
Change
String year = request.getParameter("xyear");
to
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
Reply With Quote  
Join Date: Jan 2008
Posts: 32
Reputation: electron33 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
electron33 electron33 is offline Offline
Light Poster

Re: need some help.. thanks..

  #3  
Feb 5th, 2008
Change the code in red with the following.
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Other Threads in the JSP Forum

All times are GMT -4. The time now is 9:14 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC