StringTokenizer 不知道哪里有错,帮帮忙!

xuyangqian 2003-04-08 02:47:25
<input type="submit" name="submit" value="进行查询">
</form>
<%
String submit="",sql;
submit=request.getParameter("submit");
if(submit!=null)
{
String sql_s=request.getParameter("sql");
ResultSet rs;
if(sql_s!=null)
{
sql="select * from examination where title='"+sql_s+"'";
rs=data.executeQuery(sql);
String str=rs.getString(3);
StringTokenizer st ;
st = new StringTokenizer(str);
}
%>
<form action="rewrite.jsp" method="post">
<table>
<tr>
<td>题目</td>
</tr>
<tr>
<td><input type="text" name="title" size="80" value="<%=rs.getString("title")%>">
<input type="hidden" name="id" value="<%=rs.getInt("id")%>">
</td>
</tr>
<tr>
<td>选项</td>
</tr>
<tr>
<td>
<% int count=st.countTokens();
int i=0;
while(i<4)
{
%>
<input type="text" name="content<%=i%>" size="100" value="<%=st.nextToken()%>"><br>
<% i++;
}
%>
<input type="hidden" name="count" value="<%=count%>">
</td>
</tr>
<tr>
<td>答案</td>
</tr>
<tr>
<td><input type="text" name="answer" value="<%=rs.getString("answer")%>">
</td>
</tr>
<tr>
<td>分数</td>
</tr>
<tr>
<td><input type="text" name="score" value="<%=rs.getInt("score")%>">
</td>
</tr>
<tr>
<td><input type="submit" name="submit1" value="更新数据库">
</td>
</tr>
<%
rs.close();
}%>

这只是部分的代码,错误信息为

Generated servlet error:
[javac] Compiling 1 source file

C:\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\exam\rewrite_jsp.java:115: cannot resolve symbol
symbol : variable st
location: class org.apache.jsp.rewrite_jsp
int count=st.countTokens();
^



An error occurred at line: 51 in the jsp file: /exam/rewrite.jsp

Generated servlet error:
C:\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\exam\rewrite_jsp.java:124: cannot resolve symbol
symbol : variable st
location: class org.apache.jsp.rewrite_jsp
out.print(st.nextToken());
^
2 errors

曾经我用过StringTokenizer 没有问题 不知道在这里有什么问题

...全文
7 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xuyangqian 2003-04-09
按各位的方法。但是……

C:\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\exam\rewrite_jsp.java:89: variable rs might not have been initialized
String str=rs.getString(3);
^
回复
dybine 2003-04-08
st作用域太小
回复
moumouren 2003-04-08
st的有效范只在if里面,外面的当然不能访问了,把它声明到外层把
回复
hogcheng 2003-04-08
是StringTokenizer 变量st作用域的问题,你把StringTokenizer st 放到程序的最开始就可以了
回复
cqhzq 2003-04-08
先把StringTokenizer st;这行的定义放到String submit="",sql;这行下面看看行不行。
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-04-08 02:47
社区公告
暂无公告