求教,servlet登录数据库没有东西输出

ggping66 2011-11-29 04:32:18


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;

public class login extends HttpServlet {
private Connection conn=null;
private ResultSet rst=null;
//private PreparedStatement pstm=null;
private Statement stm=null;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name=new String(request.getParameter("name").getBytes("UTF-8"),"gbk");
String pwd=new String(request.getParameter("pwd").getBytes("UTF-8"),"gbk");
response.setContentType("text/html;charset=gbk");
PrintWriter out = response.getWriter();
String sql="select * from user where u_name='"+name+"'and u_password='"+pwd+"'";

try{

stm=conn.createStatement();

rst=stm.executeQuery(sql);//问题出现在这

while(rst.next()){
out.write("登录成功");

//response.sendRedirect("login.jsp");
}
}catch(Exception e)
{
e.getStackTrace();
}
out.flush();
out.close();

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序
}
catch(ClassNotFoundException e)
{
System.out.println("找不到驱动");
}
try{
conn=DriverManager.getConnection("jdbc:odbc:ping","ggping","660309");

}
catch(SQLException e)
{
e.printStackTrace();
}

}
public void destroy() {
super.destroy();
try{ if(rst!=null) rst.close();
//if(pstm!=null)pstm.close();
if(conn!=null)conn.close();
if(stm!=null)stm.close();
}catch(Exception e)
{
e.getStackTrace();
}
}
}
...全文
69 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyy8023ych 2011-11-29
  • 打赏
  • 举报
回复
貌似 顺序错了


if(rst!=null) rst.close();
//if(pstm!=null)pstm.close();
if(conn!=null)conn.close();
if(stm!=null)stm.close();

rockay2006 2011-11-29
  • 打赏
  • 举报
回复
有报错吗?

81,114

社区成员

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

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