我用的是SQL数据库
写了一个UserMan.java的文件内容是
package kernel;
import java.sql.*;
public class UserMan{
private String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=sqldata;user=sa;password=520 ";
public UserMan(){
try{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
}
catch (Exception ex){
ex.printStackTrace();
}
}
public boolean userExist(String userID){
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
boolean exist=true;
try{
con=DriverManager.getConnection(url);
String selectStr= "select * from userat where name=? ";
ps=con.prepareStatement(selectStr);
ps.setString(1, userID);
rs=ps.executeQuery();
if (!rs.next())
exist=false;
}
catch(SQLException exc){
exc.printStackTrace();
}
finally{
if (rs!=null) try {rs.close();} catch (SQLException ignore){}
if (ps!=null) try {ps.close();} catch (SQLException ignore){}
if (con!=null) try {con.close();} catch (SQLException ignore){}
}
return exist;
}
}
然后建了一个default.htm的文件做为登录提交的,代码是
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "
"http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
</head>
<body>
<form name= "form1 " method= "post " action= "login.jsp ">
<input name= "names " type= "text " id= "names ">
<input type= "submit " name= "Submit " value= "提交 ">
</form>
</body>
</html>
来了个验证login.jsp,代码是
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<jsp:useBean id= "UserMan " scope= "page " class= "kernel.UserMan "> </jsp:useBean>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
</head>
<body>
<%
String username=request.getParameter( "names ");
if (!UserMan.userExist(username))
{
out.print( "error!! ");
}
else{
out.print( "ok!!! ");
}
%>
</body>
</html>
出现错误
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: kernel/UserMan (Unsupported major.minor version 49.0)