request.getParameter 如何传递日期

tonybao 2008-08-07 04:24:23
上一页里已有DATE变量的传递,到了本面,如何接收呢?

Date r_date = request.getParameter("r_date"); 是失败的

出错信息如下:

Type mismatch: cannot convert from String to Date

貌似request.getParameter()只可以传字符变量。。。

求助!~
...全文
931 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
tonybao 2008-08-08
  • 打赏
  • 举报
回复
现在的方法是不再将字符转成日期[received_date = df.parse((String)request.getParameter("received_date")); ]了。
发现MYSQL可以直接拿字符与日期去做判定[太好了]!

谢谢大家,结贴去!
wanglovehuang 2008-08-08
  • 打赏
  • 举报
回复
试试用 SimpleDateFormat t=new SimpleDateFormat ("yyyy-mm-dd");
t.format(r_date);这里面的参数是你传过来的值放进去
HardHardstudy 2008-08-08
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 Kit_LO 的回复:]
通过页面过来的全是字符串,你可以在后台得到值后,强制转化一下
[/Quote]
同意
Kit_LO 2008-08-08
  • 打赏
  • 举报
回复
通过页面过来的全是字符串,你可以在后台得到值后,强制转化一下
tonybao 2008-08-08
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 zhangkai08111 的回复:]
引用 13 楼 tonybao 的回复:
引用 8 楼 zhangkai08111 的回复:
引用 7 楼 zhangkai08111 的回复:
引用 4 楼 tonybao 的回复:
楼上的,再帮我看看,谢谢!

An error occurred at line: 8 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
SimpleDateFormat cannot be resolved to a type


导入包java.util.*;

不好意思错了。。
import java.text.SimpleDateFormat;
有点急

[/Quote]

经过一句句调试,现在问题就出在以下4句话间:

<%@ page import="java.text.*" %>

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

Date received_date;

received_date = df.parse((String)request.getParameter("received_date"));

出错信息是:
An error occurred at line: 8 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
Type mismatch: cannot convert from Date to Date

tracyshe 2008-08-07
  • 打赏
  • 举报
回复
用一个日期函数就好了
还比较方便,
如果楼主不是作真实项目只是想实现功能,可以不存DATE型,直接在数据库里存YEAT,MONTH,DAY
都存STRING 或INT型这样取起来是很方便的,我以前偷懒为了实现功能这样做过,
不过最好去找个日期函数
这样用起来比较好,虽然一开始可能会麻烦点但使用起来很方便
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 tonybao 的回复:]
引用 8 楼 zhangkai08111 的回复:
引用 7 楼 zhangkai08111 的回复:
引用 4 楼 tonybao 的回复:
楼上的,再帮我看看,谢谢!

An error occurred at line: 8 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
SimpleDateFormat cannot be resolved to a type


导入包java.util.*;

不好意思错了。。
import java.text.SimpleDateFormat;
有点急


出错了:
An error occurred at lin…
[/Quote]
引包都错。。。
你引包怎么写的。
TINY_LF841026 2008-08-07
  • 打赏
  • 举报
回复
DATE。TOSTRING ,然后String s=request.getParameter("date");
把。不过确实比较麻烦。呵呵
tonybao 2008-08-07
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 zhangkai08111 的回复:]
引用 7 楼 zhangkai08111 的回复:
引用 4 楼 tonybao 的回复:
楼上的,再帮我看看,谢谢!

An error occurred at line: 8 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
SimpleDateFormat cannot be resolved to a type


导入包java.util.*;

不好意思错了。。
import java.text.SimpleDateFormat;
有点急
[/Quote]

出错了:
An error occurred at line: 9 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
Syntax error on token "import", assert expected

谢谢!
tonybao 2008-08-07
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 Liebestraum 的回复:]
The type Date is ambiguous
翻开英语词典 去查下 ambiguous 这词是什么意思吧
[/Quote]

呵呵,意思明白哈,就是不知道哪儿让他老人家不高兴了。。。
tonybao 2008-08-07
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 Liebestraum 的回复:]
你System.out.println(request.getParameter("r_date"));看看 估计是获取出来的东西不符合日期格式
[/Quote]

返回的是这个:
2008-08-07

貌似是正确的
Liebestraum 2008-08-07
  • 打赏
  • 举报
回复
The type Date is ambiguous
翻开英语词典 去查下 ambiguous 这词是什么意思吧
tonybao 2008-08-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 feng8008 的回复:]
引包啊
[/Quote]

引了的呀
<%@ page import="java.util.*" %>

出错信息如下:
root cause

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 9 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
SimpleDateFormat cannot be resolved to a type

An error occurred at line: 9 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
SimpleDateFormat cannot be resolved to a type

An error occurred at line: 9 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
The type Date is ambiguous
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zhangkai08111 的回复:]
引用 4 楼 tonybao 的回复:
楼上的,再帮我看看,谢谢!

An error occurred at line: 8 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
SimpleDateFormat cannot be resolved to a type


导入包java.util.*;
[/Quote]
不好意思错了。。
import java.text.SimpleDateFormat;
有点急
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tonybao 的回复:]
楼上的,再帮我看看,谢谢!

An error occurred at line: 8 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
SimpleDateFormat cannot be resolved to a type

[/Quote]
导入包java.util.*;
Liebestraum 2008-08-07
  • 打赏
  • 举报
回复
你System.out.println(request.getParameter("r_date"));看看 估计是获取出来的东西不符合日期格式
feng8008 2008-08-07
  • 打赏
  • 举报
回复
引包啊
tonybao 2008-08-07
  • 打赏
  • 举报
回复
楼上的,再帮我看看,谢谢!

An error occurred at line: 8 in the jsp file: /maintain_collection_1_2.jsp
Generated servlet error:
SimpleDateFormat cannot be resolved to a type
Landor2004 2008-08-07
  • 打赏
  • 举报
回复
request.getParameter("r_date")方法返回的永远是字符串,所以你必须要自己转化
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d = new Date();
try{
d=df.parse((String)request.getParameter("r_date"));
}
catch(Exception e){
}
  • 打赏
  • 举报
回复
格式化日期。。
加载更多回复(1)

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧