这么简单的函数定义也能出错?JSP+TOMCAT....

xushli 2003-06-10 10:04:11
<%@ page import="java.util.*,java.text.*" %>

<%
String get_time()
{
Date now = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
return formatter.format(now);
}
String now_time=new get_time();
out.print(now_time);
%>
TOMCAT总提示我说String get_time()这里出错?

不明白,请教...
...全文
23 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Alan 2003-06-10
  • 打赏
  • 举报
回复
另外,new 方法是声明对象实例的,如果调用方法,不用加new
Alan 2003-06-10
  • 打赏
  • 举报
回复
你的函数定义部分单独列在<%!%>中
其他语句在<%%>中,将两者分开阿

错误信息打出来
acefr 2003-06-10
  • 打赏
  • 举报
回复
<%@ page import="java.util.*,java.text.*" %>

<%!
String get_time()
{
Date now = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
return formatter.format(now);
}
%>

<%
String now_time = get_time();
out.print(now_time);
%>
xushli 2003-06-10
  • 打赏
  • 举报
回复
定以函数对了,可是取得值又出错了..

String now_time=new get_time();
out.print(now_time);

其实我本意是想获取一个"2003-3-25 22:10:17"格式的变量,来和我的SQLSERVER里存储的这个格式的数据进行比较...
acefr 2003-06-10
  • 打赏
  • 举报
回复
函数的定义要用
<%!

%>
acefr 2003-06-10
  • 打赏
  • 举报
回复
faint...

错了~
acefr 2003-06-10
  • 打赏
  • 举报
回复
String get_time() = "";

81,092

社区成员

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

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