java+jsp聊天室

java+jsp聊天室,第1张

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")

String url="jdbc:microsoft:sqlserver://localhost:1433DatabaseName=Northwind"

String user="sa"

String password=""

Connection conn=DriverManager.getConnection(url,user,password)

Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE)

String sql="select * from Customers"

ResultSet rs=stmt.executeQuery(sql)

看看这段代码,就是连接数据库的代码

用户验证的话就在写一段

先半INPUT里面的值传到验证的页面,把这个值跟数据库的值进行对比,就可以了撒!

这是我写的验证代码

<%@ page import="weaver.general.Util" %>

<%@ page import="java.util.*" %>

<%@ page import="java.sql.Timestamp" %>

<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />

<jsp:useBean id="YcVerifyLogin" class="weaver.login.YcVerifyLogin" scope="page" />

<%

Date newdate = new Date()

long datetime = newdate.getTime()

Timestamp timestamp = new Timestamp(datetime)

String CurrentDate = (timestamp.toString()).substring(0,4) + "-" + (timestamp.toString()).substring(5,7) + "-" +(timestamp.toString()).substring(8,10)

String CurrentTime = (timestamp.toString()).substring(11,13) + ":" + (timestamp.toString()).substring(14,16) + ":" +(timestamp.toString()).substring(17,19)

String loginfile = Util.null2String(request.getParameter("loginfile"))

String logintype = Util.null2String(request.getParameter("logintype"))

String loginid = Util.null2String(request.getParameter("loginid"))

String logincode = Util.null2String(request.getParameter("logincode")) //验证码

String userpassword = Util.null2String(request.getParameter("userpassword"))

if(logintype.equals("")) logintype="1"

if(loginfile.equals("")) loginfile="/login/Login.jsp?logintype="+logintype

String RedirectFile = "/main.jsp"

if (logintype.equals("2")) RedirectFile = "/portal/main.jsp"

String sql=""

if(!logincode.equals(Util.getEncrypt(loginid+CurrentDate))){

response.sendRedirect(loginfile)

}

if(!loginid.equals("")){

sql="select * from ycuser where loginid='"+loginid+"' and logintype='"+logintype+"'"

RecordSet.executeSql(sql)

if(RecordSet.next()){

loginid=RecordSet.getString(1)

String usercheck = YcVerifyLogin.getUserCheck(request,response,loginid,userpassword,logintype,loginfile)

if(usercheck.equals("15") || usercheck.equals("16") || usercheck.equals("17")) response.sendRedirect(loginfile + "&message="+usercheck)

else if(usercheck.equals("19")){

response.sendRedirect("/system/InLicense.jsp?message=0")

}

else {

response.sendRedirect(RedirectFile+"?logmessage="+usercheck)

}

}else{

response.sendRedirect(loginfile)

}

}else{

response.sendRedirect(loginfile)

}

%>

希望对你有帮助!

找到连接数据库的那个类(或者是属性文件),看看它用的是什么数据库。然后确定自己电脑上装了相应的数据库。

配置tomcat很简单,点击windows->preferences->找到servers 然后选择tomcat对应的版本,我选的是6.X,然后按着提示找到tomcat的安装目录点击apply 确定就可以了


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9882978.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存