EricE
asked on
sql:dateParam problem
Hi,
I am trying to take a parameter that is passed from an earlier page:
<jsp:forward page="pnRequestNewResult.j sp">
<jsp:param name="dateAdd" value="<%= now.toString() %>"/>
</jsp:forward>
and do a query on a MySQL database on the new page:
<%
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM- dd HH:mm:ss");
DateFormat df = new DateFormat();
%>
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi n}" />
<sql:dateParam value="<% df.parse(${request.getPara meter("dat eAdd")}); %>" type="timestamp" />
</sql:query>
I'm getting an error:
org.apache.jasper.JasperEx ception: /pnRequestNewResult.jsp(20 ,66) equal symbol expected
which I assume means I'm not using the correct syntax to provide the sql:dateParam value. This worked when I wasn't using WHERE in the SELECT (no parameters).
All the examples I can find just use a request parameter directly. Need help with how to format this.
Thanks,
Eric
PS I am assuming that the position (20,66) in the error message is zero based, that is the upper left corner of the jsp page is row zero, column zero?
I am trying to take a parameter that is passed from an earlier page:
<jsp:forward page="pnRequestNewResult.j
<jsp:param name="dateAdd" value="<%= now.toString() %>"/>
</jsp:forward>
and do a query on a MySQL database on the new page:
<%
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-
DateFormat df = new DateFormat();
%>
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi
<sql:dateParam value="<% df.parse(${request.getPara
</sql:query>
I'm getting an error:
org.apache.jasper.JasperEx
which I assume means I'm not using the correct syntax to provide the sql:dateParam value. This worked when I wasn't using WHERE in the SELECT (no parameters).
All the examples I can find just use a request parameter directly. Need help with how to format this.
Thanks,
Eric
PS I am assuming that the position (20,66) in the error message is zero based, that is the upper left corner of the jsp page is row zero, column zero?
> DateFormat df = new DateFormat();
That won't work either as DateFormat is an abstract class.
Use one of it's static methods, or SimpleDateFormat instead.
That won't work either as DateFormat is an abstract class.
Use one of it's static methods, or SimpleDateFormat instead.
ASKER
Hi,
Made the change and now have another error message:
org.apache.jasper.JasperEx ception: Unable to compile class for JSP
An error occurred at line: 55 in the jsp file: /pnRequestNewResult.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh ost\accura y\pnReques tNewResult _jsp.java: 104: cannot resolve symbol
symbol : method setValue (java.util.Date)
location: class org.apache.taglibs.standar d.tag.el.s ql.DatePar amTag
_jspx_th_sql_dateParam_0.s etValue( sdf.parse(request.getParam eter("date Add")) );
^
1 error
Here is the code, only changed to SimpleDateFormat and the <sql:dateParam statement.
<%
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM- dd HH:mm:ss");
// DateFormat df = new DateFormat();
%>
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi n}" />
<sql:dateParam value="<%= sdf.parse(request.getParam eter("date Add")) %>" type="timestamp" />
</sql:query>
Is "yyyy-MM-dd HH:mm:ss" necessary when converting from a string to a Date? I got the same error with and without it.
Thanks,
Eric
PS ${conn} was set up as the datasource in some earlier code. param.txtNameLogin is the name of a text input field on the data entry page
Made the change and now have another error message:
org.apache.jasper.JasperEx
An error occurred at line: 55 in the jsp file: /pnRequestNewResult.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
symbol : method setValue (java.util.Date)
location: class org.apache.taglibs.standar
_jspx_th_sql_dateParam_0.s
^
1 error
Here is the code, only changed to SimpleDateFormat and the <sql:dateParam statement.
<%
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-
// DateFormat df = new DateFormat();
%>
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi
<sql:dateParam value="<%= sdf.parse(request.getParam
</sql:query>
Is "yyyy-MM-dd HH:mm:ss" necessary when converting from a string to a Date? I got the same error with and without it.
Thanks,
Eric
PS ${conn} was set up as the datasource in some earlier code. param.txtNameLogin is the name of a text input field on the data entry page
ASKER
Hi,
Need to clarify the error message since the caret might not be pointing to the right spot. It is pointing at the period between _jspx_th_sql_dateParam_0 and setValue(sdf...).
Eric
Need to clarify the error message since the caret might not be pointing to the right spot. It is pointing at the period between _jspx_th_sql_dateParam_0 and setValue(sdf...).
Eric
Try:
<sql:dateParam value="<%= new java.sql.Date(sdf.parse(re
ASKER
Hi,
Looks like the same error message:
An error occurred at line: 55 in the jsp file: /pnRequestNewResult.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh ost\accura y\pnReques tNewResult _jsp.java: 104: cannot resolve symbol
symbol : method setValue (java.sql.Date)
location: class org.apache.taglibs.standar d.tag.el.s ql.DatePar amTag
_jspx_th_sql_dateParam_0.s etValue( new java.sql.Date(sdf.parse(re quest.getP arameter(" dateAdd")) .getTime() ) );
^
1 error
Code is:
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi n}" />
<sql:dateParam value="<%= new java.sql.Date(sdf.parse(re quest.getP arameter(" dateAdd")) .getTime() ) %>" type="timestamp" />
</sql:query>
I cleared out the work subdirectory and restarted Tomcat to make sure it wasn't using the cached files.
Thanks,
Eric
Looks like the same error message:
An error occurred at line: 55 in the jsp file: /pnRequestNewResult.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
symbol : method setValue (java.sql.Date)
location: class org.apache.taglibs.standar
_jspx_th_sql_dateParam_0.s
^
1 error
Code is:
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi
<sql:dateParam value="<%= new java.sql.Date(sdf.parse(re
</sql:query>
I cleared out the work subdirectory and restarted Tomcat to make sure it wasn't using the cached files.
Thanks,
Eric
try this:
<fmt:parseDate value="${param.dateAdd}" var="parsedAddDate"
pattern="yyyy-MM-dd" />
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi n}" />
<sql:dateParam value="${parsedAddDate}" type="timestamp" />
</sql:query>
<fmt:parseDate value="${param.dateAdd}" var="parsedAddDate"
pattern="yyyy-MM-dd" />
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi
<sql:dateParam value="${parsedAddDate}" type="timestamp" />
</sql:query>
ASKER
Hi,
Seem to be stuck in an infinite loop... When I made the change you suggested I get an error:
org.apache.jasper.JasperEx ception: In <parseDate>, value attribute can not be parsed: "Mon Mar 03 21:36:41 GMT-08:00 2003"
So I go back to the page that stuffs the parameter with:
<jsp:forward page="pnRequestNewResult.j sp">``
<jsp:param name="dateAdd" value="${parsedAddDate}"/>
</jsp:forward>
and try to use fmt:parseDate to put the string date in a simpiler format. I was able to do that according to:
<% out.println(sdf.format(fmt Date)); %>
but I still end up trying to put Java code into a value statement, in this case in the fmt:parseDate:
<fmt:parseDate value=" ${<% sdf.format(fmtDate)); %>} " var="parsedAddDate" pattern="yyyy-MM-dd HH:mm:ss" /> (one of my failed attempts)
so I can pass it to jsp:forward. The fundamental problem seems to be how do you pass a variable you have defined in regular Java code into the parameter value of a taglib??
Gotta crash now, getting old... Appreciate any futher thoughts.
Thanks,
Eric
PS I have the book and have that page open in Opera, unfortunately it doesn't get any more complex than the examples at Sun, just uses request parameters.
Seem to be stuck in an infinite loop... When I made the change you suggested I get an error:
org.apache.jasper.JasperEx
So I go back to the page that stuffs the parameter with:
<jsp:forward page="pnRequestNewResult.j
<jsp:param name="dateAdd" value="${parsedAddDate}"/>
</jsp:forward>
and try to use fmt:parseDate to put the string date in a simpiler format. I was able to do that according to:
<% out.println(sdf.format(fmt
but I still end up trying to put Java code into a value statement, in this case in the fmt:parseDate:
<fmt:parseDate value=" ${<% sdf.format(fmtDate)); %>} " var="parsedAddDate" pattern="yyyy-MM-dd HH:mm:ss" /> (one of my failed attempts)
so I can pass it to jsp:forward. The fundamental problem seems to be how do you pass a variable you have defined in regular Java code into the parameter value of a taglib??
Gotta crash now, getting old... Appreciate any futher thoughts.
Thanks,
Eric
PS I have the book and have that page open in Opera, unfortunately it doesn't get any more complex than the examples at Sun, just uses request parameters.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would suggest you to user request scope bean to pass your date, in forwarding page:
<%request.setAttribute( "dateAdd", now );%>
<jsp:forward page="pnRequestNewResult.j sp" />
or if your prefer tags:
<jsp:useBean id="dateAdd" class="java.util.Date", scope="request" />
<jsp:forward page="pnRequestNewResult.j sp" />
in pnRequestNewResult.jsp:
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi n}" />
<sql:dateParam value="${dateAdd}" type="timestamp" />
</sql:query>
<%request.setAttribute( "dateAdd", now );%>
<jsp:forward page="pnRequestNewResult.j
or if your prefer tags:
<jsp:useBean id="dateAdd" class="java.util.Date", scope="request" />
<jsp:forward page="pnRequestNewResult.j
in pnRequestNewResult.jsp:
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi
<sql:dateParam value="${dateAdd}" type="timestamp" />
</sql:query>
ASKER
Hallelujah,
I'd swear I tried that syntax for passing in the value to the forward tag but I was flailing around pretty badly.
Thanks for the alternative Kenneth, I've copied it to comments on the page and will remember for future use.
Thanks,
Eric
I'd swear I tried that syntax for passing in the value to the forward tag but I was flailing around pretty badly.
Thanks for the alternative Kenneth, I've copied it to comments on the page and will remember for future use.
Thanks,
Eric
<sql:query var="rs" scope="request" dataSource="${conn}">
SELECT * FROM partnumber WHERE sNameUser = ? AND tDateRqst = ?
<sql:param value="${param.txtNameLogi
<sql:dateParam value="<%= df.parse(request.getParame
</sql:query>
Though I'm not sure what you intend with:
${conn}
${param.txtNameLogin}