初学JSP,为啥定义JS变量时出错了?

jrjx13143344 2009-08-06 01:00:04
初学,烦请各位帮忙看看
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page language=javascript %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%!
tim = "本地时间"; --红XX打在这行
%>
<html>
<head>
<title>My JSP 'MyJsp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>
<body>
This is my JSP page. <br>
<% out.println("1+2="+tim); %>
</body>
</html>
...全文
73 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fish200x 2009-08-06
  • 打赏
  • 举报
回复
呵呵,好好去看下书吧,这种问题其实书上都有
iamhost 2009-08-06
  • 打赏
  • 举报
回复
看错了,不好意思。
<%!
String tim = "本地时间"; //--红XX打在这行
%>
<%
out.print("1+2="+tim);
%>
这样写吧。
iamhost 2009-08-06
  • 打赏
  • 举报
回复
他写的这根本不是js,只是一个简单的jsp页面。
<%!
String tim = "本地时间"; --红XX打在这行
%>
<%
out.print("1+2="+tim);
%>

这样写试一下。
simple_pai 2009-08-06
  • 打赏
  • 举报
回复
你的js都没有被包含在<script></script>内
而且tim 应该先声明下吧~ var tim~

晚安~~~~~~

81,114

社区成员

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

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