帮我解决个小问题啊

myjerry 2011-01-20 03:10:25
我装的是jdk 1.6.0_18,tomcat6,
我做了个jsp,代码如下:
<%@ page contentType="text/html;charset=utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ex4-4</title>
</head>

<body>

<%! int num = 0;
void countnum() {
num++;
}
%>
<% countnum(); %>
<h3>变量num的值现在为:</h3>
<br/>
<br/>
<h1><% =num; %></h1>
</body>
</html>

结果运行有问题:
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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

An error occurred at line: 13 in the jsp file: /ex4-4.jsp
Syntax error, insert ";" to complete BlockStatements
10:
11: <%! int num = 0;
12: void countnum() {
13: num++
14: }
15: %>
16: <% countnum(); %>


An error occurred at line: 16 in the jsp file: /ex4-4.jsp
Syntax error on token ";", Expression expected after this token
13: num++
14: }
15: %>
16: <% countnum(); %>
17: <h3>鍙橀噺num鐨勫�鐜板湪涓猴細</h3>
18: <br/>
19: <br/>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.

Apache Tomcat/6.0.24

请大家帮我看看到底我哪里出错了?
如果jsp部分全部写在一块,是能正确运行的。
...全文
219 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
beowulf2005 2011-01-26
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 myjerry 的回复:]

我是初学者,这代码可是照抄书上的了

<%@ page contentType="text/html;charset=GB2312" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>ex4-4</title>
</head>
<%! int……
[/Quote]
<%=num %>
百分号和等号之间不要空格
山鹰 2011-01-26
  • 打赏
  • 举报
回复
输出变量没有分号
<%=num%>
waitdream 2011-01-26
  • 打赏
  • 举报
回复
盗版书害死人啊!
  • 打赏
  • 举报
回复
楼主要努力掌握java基础
li463968565 2011-01-26
  • 打赏
  • 举报
回复
[code=HTML]
<!-- SCItem开始 --> <% int a=0; a++;%><c:forEach items="${getOne }" var="q" varStatus="qq">
<table id="SCItem_Table" cellpadding="0" cellspacing="3" border="0" width="100%">
<tbody id="SCItem_Tbody">
<tr id="SCItem_Tr_${qq.index+1}">
<td>
<table cellpadding="0" cellspacing="0" border="1" width="100%">
<tr style="background:#DCD8E7;">
<td width="3%"> No.
<input type="text" value="<%=a %>"/>
<h1>
<%=a %>
</h1>[/
code]
>
myjerry 2011-01-26
  • 打赏
  • 举报
回复
谢谢后面的几位大虾,非常谢谢!
我是初学的,很多不懂。以前用asp的,汗
jmhong66 2011-01-26
  • 打赏
  • 举报
回复
楼上正解。
kevin#1 2011-01-26
  • 打赏
  • 举报
回复

<%@ page contentType="text/html;charset=GB2312"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>ex4-4</title>
</head>
<%! int num = 0;

void countnum() {
num++;
}%>
<%
countnum();
%>
<body>
<h3>
变量num的值现在为:
</h3>
<br />
<br />
<h1>
<%=num%>
</h1>
</body>
</html>

qkniit 2011-01-26
  • 打赏
  • 举报
回复
[Quote=引用楼主 myjerry 的回复:]
12: void countnum() {
13: num++
14: }
[/Quote]

num++ 后面没分号????????
liuchao1989 2011-01-26
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 beowulf2005 的回复:]
引用 10 楼 myjerry 的回复:

我是初学者,这代码可是照抄书上的了

<%@ page contentType="text/html;charset=GB2312" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>ex4-4</t……
[/Quote]+1
myjerry 2011-01-25
  • 打赏
  • 举报
回复
唉,一个小问题啊
  • 打赏
  • 举报
回复
采用 debug调试





希望对你有帮助
asura11 2011-01-23
  • 打赏
  • 举报
回复
书上的不一定都是对的,还是自己慢慢的查找看哪里有错误,这样才能提高
myjerry 2011-01-23
  • 打赏
  • 举报
回复
我是初学者,这代码可是照抄书上的了

<%@ page contentType="text/html;charset=GB2312" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>ex4-4</title>
</head>
<%! int num = 0;
void countnum() {
num++;
}
%>
<% countnum(); %>
<body>
<h3>变量num的值现在为:</h3>
<br/>
<br/>
<h1><% =num %></h1>
</body>
</html>

可还是有错误:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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

An error occurred at line: 17 in the jsp file: /ex4-4.jsp
Syntax error on token "=", @ expected
14: <h3>变量num的值现在为:</h3>
15: <br/>
16: <br/>
17: <h1><% =num %></h1>
18: </body>
19: </html>


An error occurred at line: 17 in the jsp file: /ex4-4.jsp
Syntax error on token(s), misplaced construct(s)
14: <h3>变量num的值现在为:</h3>
15: <br/>
16: <br/>
17: <h1><% =num %></h1>
18: </body>
19: </html>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.

Apache Tomcat/6.0.24


的确不知道哪里有问题啊。楼上高人,能否帮我代码调试下?
我不知道会不会是我哪里配置有问题,还是哪里的符号标记有问题?
xxy8100 2011-01-20
  • 打赏
  • 举报
回复
void countnum() {
num++ ; //在这里加个分号
}
Hamiltion 2011-01-20
  • 打赏
  • 举报
回复
兄弟仔细点儿,你是不是在有多删除了一个'}'啊,你的问题在ide中是可以反映出来的
不是大家不想帮你,而是,有问题要先自己想办法解决,仔细分析问题,这样你才可以
提高啊!
myjerry 2011-01-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 eaglehacker 的回复:]

各种错 初学的吧
[/Quote]

有错帮我指出来嘛,谢谢
myjerry 2011-01-20
  • 打赏
  • 举报
回复
谢谢,各位。我的确是初学者,很多该注意的地方不知道。
我现在把
<h1><% =num; %></h1>
里的分号去掉了,出现如下错误:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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

An error occurred at line: 13 in the jsp file: /ex4-4.jsp
Syntax error, insert "}" to complete MethodBody
10:
11: <%! int num = 0;
12: void countnum() {
13: num++;
14:
15: %>
16: <% countnum(); %>


An error occurred at line: 20 in the jsp file: /ex4-4.jsp
Syntax error on token "=", @ expected
17: <h3>鍙橀噺num鐨勫�鐜板湪涓猴細</h3>
18: <br/>
19: <br/>
20: <h1><% =num %></h1>
21: </body>
22: </html>


An error occurred at line: 20 in the jsp file: /ex4-4.jsp
Syntax error on token(s), misplaced construct(s)
17: <h3>鍙橀噺num鐨勫�鐜板湪涓猴細</h3>
18: <br/>
19: <br/>
20: <h1><% =num %></h1>
21: </body>
22: </html>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.
  • 打赏
  • 举报
回复
我那个去 你抄人家的代码? 要报错的啊 不可能 不知道。
wangjiangbo2 2011-01-20
  • 打赏
  • 举报
回复
恩,1楼指的问题是个错误
加载更多回复(3)

81,090

社区成员

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

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