新手,各种错误,郁闷,求指教

qingying1 2013-06-16 04:01:46
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<jsp:directive.page import="java.sql.DriverManager"/>
<jsp:directive.page import="java.sql.Connection"/>
<jsp:directive.page import="java.sql.Statement"/>
<jsp:directive.page import="java.sql.ResultSet"/>
<jsp:directive.page import="java.sql.Date"/>
<jsp:directive.page import="java.sql.Timestamp"/>
<jsp:directive.page import="java.sql.SQLException"/>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.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>
<a href="addPerson.jsp">新建人员资料</a>
<%
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;

try{
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/databaseWeb","root","1992618");
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from tb_person");

%>
<form action="operatePerson.jsp" method=get>
<table bgcolor="#CCCCCC" cellspacing=1 cellpadding=5 width=100%>
<tr bgcolor=#DDDDDD>
<th></th>
<th>ID</th>
<th>姓名</th>
<th>英文名</th>
<th>性别</th>
<th>年龄</th>
<th>生日</th>
<th>备注</th>
<th>记录创建时间</th>
</tr>
<%
while (rs.next()){
int id=rs.getInt("id");
int age=rs.getInt("age");
String name=rs.getString("name");
String english_name=rs.getString("english_name");
String sex=rs.getString("sex");
String description=rs.getString("description");
Date birthday=rs.getDate("birthday");
Timestamp createTime=rs.getTimestamp("create_time");
out.println("<tr bgcolor=#FFFFFF>");
out.println("<td><input type=checkbox name=id value="+id+"></td>");
out.println("<td>"+id+"</td>");
out.println("<td>"+name+"</td>");
out.println("<td>"+english_name+"</td>");
out.println("<td>"+sex+"</td>");
out.println("<td>"+age+"</td>");
out.println("<td>"+birthday+"</td>");
out.println("<td>"+description+"</td");
out.println("<td>"+createTime+"</td>");
out.println("<td>");
out.println("<a href='operatePerson.jsp?action=del&id="+id+"'onclick='return confirm(\"确定删除该记录?\")'>删除</a>");
out.println("<a href='operatePerson.jsp?action=edit&id="+id+"'>修改</a>");
out.println("</td>");
out.println("</tr>");
}
%>
</table>
<table align=left>
<tr>
<td>
<input type=hidden value='del' name='action'>
<a href='#' onclick="
var array=document.getElementByName('id');
for(var i=0;i<array.length;i++){
array[i].checked=true;
}">全选
</a><a href='#'onclick="var array=document.getElementByName('id');for(var i=0;i<array.length;i++){array[i].checked=false;}">取消全选</a>
<input type='submit' onclick='return confirm(\"即将删除所选择的记录。是否删除?\")'value='删除'>
</td></tr></table></form>
<%
}catch(SQLExceptioin e){
out.println("发生了异常:"+e.getMessage());
e.printStackTrace();
}
finally{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}%>
</body>
</html>
出现的错误:Multiple annotations found at this line:
- Syntax error, insert ") Statement" to complete
ForStatement
- Attribute value (
var array=document.getElementByName('id');
for(var i=0;i<array.length;) not closed.
- Syntax error, insert ") Statement" to complete
ForStatement
- Attribute value (
var array=document.getElementByName('id');
for(var i=0;i<array.length;) not closed.


Multiple annotations found at this line:
- Cannot return from outside a function or
method.

SQLExceptioin cannot be resolved to a type

求教啊,在线等
...全文
334 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
melodyfair1971 2013-07-06
  • 打赏
  • 举报
回复
一次过混得东西太多了,刚学不太容易调试。 1.首先,只需要连接数据库的代码 是否出错 2.再输出 数据库的记录 是否出错 3.再用js
u010457992 2013-07-05
  • 打赏
  • 举报
回复
先用控制台把错误打印出来看看是啥,这发源代码找错误犹如大海捞针!
qingying1 2013-07-05
  • 打赏
  • 举报
回复
我是自学的,书是Javaweb整合开发王者归来,书很厚,但感觉讲的都不到位,,,,, 求推荐啊,去哪找资料?
软件人 2013-07-03
  • 打赏
  • 举报
回复
jsp里面最好是避免java代码,都不知道楼主看的是什么时候的书籍,现在java的规范比以前的好多了。 又是一个受伤害的人,看的啥书嘛,怎么这样去些。mvc思想一点没用手,别人是现代人,你都学到原始人去了。 学习资料自己看看吧,看看别人讲的东西,对比下你看的书,学习不要太盲目,尽信书和尽信视频都是不可取的。 还是自己多实践,多测试。 http://java.itcast.cn/java/video.shtml?130703wwt&csdn
  • 打赏
  • 举报
回复
SQLExceptioin cannot be resolved to a type你这单词都写错了,SQLException
z744489075 2013-07-03
  • 打赏
  • 举报
回复
你们老师还是80年代搞编程的吧?然后一直被冰封。最近才出来教书的
z744489075 2013-07-03
  • 打赏
  • 举报
回复
你们老师还是80年搞编程的吧?然后一直被冰封。最近才出来教书的
  • 打赏
  • 举报
回复
无法直视的代码~~
wyx100 2013-06-17
  • 打赏
  • 举报
回复
chen719521498chen719521498等级: #6得分:0 回复于: 2013-06-16 23:46:21 你把SQLException改成Exception, 把另外两个的<% %>写在wile(){}的前后。试下 别外,你写的document.getElementByName('id'),当结果rs为空的时候,页面中没有加载到id的checkbox对象,你这样写是会报错的(因为页面中没有id的这个对象)。
qingying1 2013-06-17
  • 打赏
  • 举报
回复
引用 7 楼 shxt_xiaozhi 的回复:
把js代码写到方法中吧,好像就是onclick那里的问题
<input type='hidden' value='del' name='action'> <a href='#' onclick=" <script language="JavaScript" type="text/JavaScript" > var array=document.getElementByName('id'); for(var i=0; i < array.length;i++){array[i].checked=true;} </script>">全选</a> <a href='#' onclick=" <script language="JavaScript"type="text/JavaScript"> var array=document.getElementsByName('id'); for(var i=0; i < array.length;i++){ array[i].checked=false;} </script>">取消全选</a> <input type='submit' onclick='return confirm(\"即将删除所选择的记录。是否删除?\"); ' value='删除'> 果真解决了,真谢谢啊! 连后面的return confirm 问题也解决了,这是怎么回事? 不知道还可以<a href <script> </script> > </a> 这样嵌套标记也是合法的? 之前出现了com.mysql can't be resolved to a type后来忘记怎么弄得,这个错误 消除了,出现了后面的SQLException can't be resolved to a type 现在我重新装了myeclipse tomcat mysql 有出现了这个问题,而且没有了SQLException can't be resolved to a type 求解决
菖蒲老先生 2013-06-17
  • 打赏
  • 举报
回复
document.getElementsByName('id');
且活且珍惜 2013-06-17
  • 打赏
  • 举报
回复
把js代码写到方法中吧,好像就是onclick那里的问题
biq园 2013-06-16
  • 打赏
  • 举报
回复
你把SQLException改成Exception, 把另外两个的<% %>写在wile(){}的前后。试下 别外,你写的document.getElementByName('id'),当结果rs为空的时候,页面中没有加载到id的checkbox对象,你这样写是会报错的(因为页面中没有id的这个对象)。
qingying1 2013-06-16
  • 打赏
  • 举报
回复
那之前的DriverManager connection statement都没有显示出错? 是我自己看的,JavaWeb整合开发,书上不少例子都无法运行
jsonbor 2013-06-16
  • 打赏
  • 举报
回复
SQLException can't be resolved to a type?是说你这个SQL连接数据库出错了!
昵称被占用 2013-06-16
  • 打赏
  • 举报
回复
JSP页面写数据库访问,这是什么老师教的!
qingying1 2013-06-16
  • 打赏
  • 举报
回复
我是新手,看书上就是这样写的,不过好像别人写的,都是在一个Java类中,为什么不能写在jsp中? 还有,为什么会说SQLException can't be resolved to a type? return confirm () 为什么会报错? for语句后面的',’为什么也报错? <需要转义符这个已经改过来了
寻找鱼钩的鱼 2013-06-16
  • 打赏
  • 举报
回复
连接数据库怎么写在JSP页面

81,092

社区成员

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

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