日期:2014-05-20 浏览次数:20708 次
package com.nong; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; public class Lgcl extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException { res.setContentType("text/html;charset=gbk"); PrintWriter pw=res.getWriter(); Connection ct=null; Statement sm=null; ResultSet rs=null; pw.println("aaa"); try{ String u=req.getParameter("username"); String p=req.getParameter("passwd"); Class.forName("com.microsoft.jdbc.sqlserver.SqlserverDriver"); ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1434;DatabaseName=Mybase","sa","long"); sm=ct.createStatement(); rs=sm.executeQuery("select * from user where users='"+u+"' and pwd='"+p+"'"); if(rs.next()) { pw.println("登录成功"); } else { pw.println("登录失败"); } } catch(Exception e) { e.printStackTrace(); } finally { try{ if(rs!=null){rs.close();} if(sm!=null){sm.close();} if(ct!=null){ct.close();} } catch(Exception e) { e.printStackTrace(); } } } public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException { this.doGet(req,res); } }