查询后的数据库操作问题,找不出什么错误,还望各位帮忙一下!

zmkun 2004-09-10 12:19:44
其中的JAVABEAN的setInsert是执行executeUpdate的,setRs与getRs是得到查询值的,已经证实没有问题,其中query.jsp执行正常,可是删除与修改会出现如下的错误:
exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:315)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:258)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:205)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.NullPointerException
org.apache.jsp.modify_jsp._jspService(modify_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:268)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:258)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:205)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
...全文
56 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zmkun 2004-09-12
To vampirewp():THANKS!!!解决了!!!!
回复
zmkun 2004-09-10


query.jsp:
<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="com.xmgd.sql.*" %>
<html>
<head>
<title>
query
</title>
</head>
<body bgcolor="#ffffff">
<h1>
</h1>
<jsp:useBean id="test" class="com.xmgd.sql.OperSql" scope="session" />
<%
test.connect();
String getType=request.getParameter("filmtype");
String getLocation=request.getParameter("location");
int type,location;
if(getType.equals("movie")) type=1;
else type=2;
if(getLocation.equals("vod")) location=1;
else if(getLocation.equals("db")) location=2;
else location=3;
String input="SELECT * from movie WHERE "+"progtype="+type+" AND "+"filelocation="+location;
test.setRs(input);
ResultSet rs;
rs=test.getRs();
%>
<center>
<font size=5>你所选择的位置为:<%=request.getParameter("location") %>
所选择的类型为:<%=request.getParameter("filmtype") %>
</font>
<br>
<table bgcolor=yellow width="500" border="1" height="60">
<tr bgcolor=silver>
<td><b>请选择</b></td><td><b>文件名</b></td><td><b>影片名</b></td>
</tr>
</td>
</center>
<%
while(rs.next()){
String filename=rs.getString("filename");
String id=rs.getString("id");
%>
<center>
<form method=post action="modify.jsp">
<td><b>
<p>
<input type="checkbox" name="choice" value="<%=id %>"/></b></td>
<td><b><%=rs.getString("filename")%></b>
</td>
<td><b><%=rs.getString("progname")%></b>
</td>
</tr>
</p>
</center>
<%
}
%>
<input type="submit" name="submit1" value="删除">
<center> 改变位置至:
<select name="local">
<option value="--" selected>--</option>
<option value="vod">VOD</option>
<option value="db">DB</option>
<option value="nas">NAS</option>
<input type="submit" name="submit2" value="确定改变">
</center>
<% while(!rs.next())

{ %>
<center>
<p>
<font size="4" color=red>
</font>
</p>
</center>
<% break;
}
%>
</table>
</form>
</body>
</html>

modify.jsp:
<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.xmgd.sql.*" %>
<html>
<head>
<title>
delete
</title>
</head>
<body bgcolor="#ffffff">
<h1>
</h1>
<jsp:useBean id="test" class="com.xmgd.sql.OperSql" scope="session">
</jsp:useBean>
<%
test.connect();
String check1=request.getParameter("submit1");
String check2=request.getParameter("submit2");
String[] id=request.getParameterValues("id");
int size=id.length;
if(check1!=null){
if(id!=null){
System.out.println("hello");
for(int i=0;i<size;i++){
String update="delete * from movie where "+"id="+id[i];
test.setInsert(update);
}
}else{
System.out.println("hello1");
%>
<center><font size=5>请选择所要删除的节目!
</center></font>
<%
}
}
if(check2!=null){
int location;
String chLocation=request.getParameter("local");
if(chLocation.equals("vod")) location=1;
else if(chLocation.equals("db")) location=2;
else location=3;
if(id!=null){
for(int i=0;i<size;i++){
String update="update movie set "+"location="+location+
" where "+"id="+id[i];
test.setInsert(update);
}
}else{
}
}
%>
</body>
</html>
回复
vampirewp 2004-09-10
<%
while(rs.next()){
String filename=rs.getString("filename");
String id=rs.getString("id");
%>
<center>
<form method=post action="modify.jsp"> //
<td><b>
<p>
<input type="checkbox" name="choice" value="<%=id %>"/></b></td>
<td><b><%=rs.getString("filename")%></b>
</td>
<td><b><%=rs.getString("progname")%></b>
</td>
</tr>
</p>
</center>
<%
}
%>

在这一段的<form>标记应该要放到while之前,
因为你的checkbox 的name属性为choice,所以你在modify.jsp文件中应该用
getParameterValues("choice")来获取值

在modify.jsp文件中有一个bug
int size=id.length;
当在query.jsp页面没有选中值时,此时id数组就会null ,从而导致抛出空指针异常

回复
zmkun 2004-09-10
不对吧,我的submit1是submit(提交)的,只是想得到checkbox是否选择的情况;select name="local"是下拉菜单,想得到新的位置,接下去用submit2提交上去的.
回复
pakeyfanyin 2004-09-10
SUBMIT1错了,你应该<SELECTE name=sumit1.....>
而你是<input type=submit name=submit1...>当然是没有值的了
回复
zmkun 2004-09-10
查出来了,在modify.jsp中的getParameterValues("id")值为null.不过在Query.jsp里面checkbox已经选了,为什么也还是NULL呢?submit1没有错误吧?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-10 12:19
社区公告
暂无公告