我自已试着写会员验证的代码,刚开始用BEAN出错,然后我把驱动写在页面里,结果还是有问题,不管输入的用户名和密码对不对他都跳到下个页面!!疯掉了!帮忙看看那里有问题
String driver ="org.gjt.mm.mysql.Driver";
String url="jdbc:mysql://localhost:3306/news?characterEncoding=GB2312";
String user="root";
String password="123456";
Connection con=null;
ResultSet rs=null;
Class.forName(driver);
con = DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
String sql="select * from admin where name='"+name+"'and password='"+pass+"'";
rs=stmt.executeQuery(sql);
if (rs!=null)
{
session.setAttribute("name",name);
response.sendRedirect("news.jsp");
}
else
{
out.print("你的用户名有误");
}
String driver ="org.gjt.mm.mysql.Driver";
String url="jdbc:mysql://localhost:3306/news?characterEncoding=GB2312";
String user="root";
String password="123456";
Connection con=null;
ResultSet rs=null;
Class.forName(driver);
con = DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
String sql="select * from admin where name='"+name+"'and password='"+pass+"'";
rs=stmt.executeQuery(sql);
if (rs!=null)
{
session.setAttribute("name",name);
response.sendRedirect("news.jsp");
}
else
{
out.print("你的用户名有误");
}
解决方案 »
- 很初级的问题 Servlet Filter错误
- 简单问题 [在线等]
- 如何给FCKEditor编辑器配置里增加一个属性?
- 可支持1亿pv/天的超级数据库缓存系统,首发开源了。
- 左右两个<td>因为内容长度不一样导致不能对顶对齐
- 如何在所有jsp页面,设置一个公共变量。
- struts action中如何得到jsp中的action参数和target参数
- 一个关于按权限下载文件的问题
- 本人最近将网页从SOLARIS服务器移植到LINUX服务器,出现了中文显示问题,但我又不想用s.getBytes("8859_1"),"GB2312")逐个修改,不知那位高
- 求解,JSP做一个投票系统,要求要用到sevelet…
- 有没有简洁的虚拟机安装
- 树结构存储
while(rs.next()){
username = rs.getString("name");
}if(username != null) {
...
}else{
...
}
改成
if(rs.next())在rs中,本身它就有一条内容,所以它不管查询到与否,它是非空的。