给你举一个简单的案例,在这个例子中,onclick用来判断用户名不可以为空,然后通过单击登陆按钮进行触发判断,仅供参考
<%@ page language="java" import="java.util.*,java.sql.*" contentType="text/html; charset=gb2312"%>
Insert title here<%
String s_name=request.getParameter("name");
String s_password=request.getParameter("password");
String c="未登录";
String s_select=request.getParameter("select");
String d="2";
if(s_name!=null&&s_password!=null)
{
Connection ct=null;
try{
//1加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
c="0";
//2得到连接
ct=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=ls","sa","123");
c="1";
//3创建Statement
Statement sm=ct.createStatement();
c="2";
//4查询
ResultSet rs=sm.executeQuery("select userId,password from login where name='"+s_name+"'");
c="3";
if(rs.next())
{
c="4";
c=rs.getString(2);
d=rs.getString(1);
if(rs.getString(2).trim().equals(s_password.trim()))
{
c="欢迎登陆";
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
%>
欢迎登陆服装连锁系统