Link to home
Start Free TrialLog in
Avatar of jwalthour
jwalthourFlag for United States of America

asked on

Input parameter comes up null in getParameter

cos-edit.jsp.txtcos-edit.jsp.txtI have a JSP page I'm writing to do basic DML on a table in Oracle. The row I'm editing is in a form, each cell being an input parameter. The submit refreshes the page, does the insert or update, then requeries the table with the updated data. All my input parameters except one can be read from getParameter on the refresh. I can't figure out why the one--ScheduledDate-- always comes back null. From what I can see, I'm doing the same thing with it that I'm doing with all the others. I've attached my jsp. Can anyone point out to me what I'm missing? Thanks in advance, Experts!
Avatar of mrcoffee365
mrcoffee365
Flag of United States of America image

When you do the request.getParameter("ScheduledDate") the code works fine and gets the value of ScheduledDate from the form.  You should put some debugging in your code -- write to a log, or step through it with eclipse.   You'll see the input value.

However, you do odd things -- there aren't any insert or update commands.  See this documentation on how to use preparedstatement:
http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html

What you think of as "no value for ScheduleDate" might be that inserts and updates are not happening.

You are not printing your exceptions --  either use e.printStackTrace() or do something else so that you can see your errors.  We don't have your db, so it's hard to say, but when I try a version of your code it gets errors in the preparedstatement handling and subsequent selects.

In Java, the naming convention is to name variables with a leading lowercase letter, so the variable ScheduledDate should be scheduledDate .   Classes start with an uppercase letter.   It would make your code more readable to follow the naming conventions.
Avatar of jwalthour

ASKER

What I've done for debugging is to put some simple writing out of the parameters in the HTML after the getParameter.

ScheduledDate = request.getParameter("ScheduledDate");
%>
<!%ScheduledDate%>
<%

At that point, what is displayed is "null". So, I know, after the submit and refresh. the value isn't there. The other parameters are, just not this one. So, the problem seems to be between the assignment of the palue to the parameter and the getParameter call -- before the PreparedStatement.

Yes, I should probably cleanup the code. I'm a DBA by trade who just uses jsp's as part of my own work--not for anyone beyond myself. I've never studied jsp beyond learning what I need to do what I want to do. So, I don't know the standards.

The "select" statement is actually a call to a procedure which standardizes the input and then runs a merge statement to insert or update the data in the table. I've used prepared statements to do inserts and updates, but wasn't sure how to use them for calling a procedure. The "select" got around that for me.
Well, when I run your code there's a value in request.getParameter("ScheduledDate") .  I can tell because I write the value to a log with a statement like:
System.out.println("ScheduledDate = " + ScheduledDate);

This is not what you wanted:
<!%ScheduledDate%>

I don't think that will even compile, so I'm not sure what that would do.

If you wanted to see the results in the output HTML for the page, then you would put something like this:
ScheduleDate = <%=ScheduledDate%>
And to see it on the page, that line  would have to be within the <body></body> tags.
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!
Did you know that you can award points to all the experts who helped you, especially those who gave you the answer first?  This help page explains how to choose multiple experts for awarding points:
https://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=24