当前位置:编程学习 > JSP >>

jsp 数据更新问题? 为什么更新后数据没变??

下面是更新页面的代码, 等成功跳转到response.sendRedirect("M_user_in.jsp"); 但是,数据并没有变化,谁能帮我解答一下 <%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <jsp:useBean id="wu" scope="page" class="wu.jdbc" /> <body> <% String login = (String)session.getAttribute("login") ; if(login==null){ out.println("您不是管理员!不能登陆删除"); }else{ Connection con = wu.getConn() ; Statement stmt = con.createStatement() ; String id = request.getParameter("id") ; String name=request.getParameter("Username"); String Password =request.getParameter("Psd1"); //content = wu.ex_chinese(content) ; String Company =request.getParameter("Companyname"); // qq = wu.ex_chinese(addr) ; String Rname =request.getParameter("Rename"); // qq = wu.ex_chinese(tel) ; //int tel = (int) tel ; String Email =request.getParameter("Email"); String Phone =request.getParameter("Phone"); String sql = "update alluser set username='"+name+"',password='"+Password+"',company='"+Company+"',rname='"+Rname+"',email='"+Email+"',phone='"+Phone+"' where id="+id; int rs=stmt.executeUpdate(sql); try { stmt.close(); con.close(); } catch (Exception ex) { } response.sendRedirect("M_user_in.jsp"); } %> </body> </html>
追问:数据没有更新成功,不知道是哪的问题能具体说一下吗?那怎么 吧password 等参数传递过去啊?
答案:你是直接运行的本页面对吗?
你想想看,你是直接用request.getParameter来获取你的值的,可是request里头有这些个值吗?
           能具体说一下吗?那怎么 吧password 等参数传递过去啊?
你可以这样保存你的参数:
1.在本页面,使用request.setParameter来保存你的bassword等参数;然后就可以取到了.
2.在跳转到本页面前保存此参数至request,可以手动的request.setParameter;也可以使用struts等.
还有,建议你的跳转页面不要这么写,而要收集你的sql运行后的结果,如果sql执行成功了,页面跳转;如果sql没执行成功,可以提示信息,不跳转.
不知道我说的你能不能理解.
其他:数据更新成功了? 直接运行check.jsp报错是正常的,因为request请求中不存password和username参数.也就是说没有表达对象传过来.娶不到参数对象就报空指针错误了.
连接不上数据库,是不是你的数据库tcp端口默认没有改为1433啊,
还是没导入 sqlserver驱动包,
也没贴出具体哪一行错误,我也不好说
 那你的数据库里的数据更新成功了没 

上一个:jsp(HTNL) SELECT选择框鼠标滚动选项
下一个:JSP共享数据范围从小到大的排列顺序是:

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,