📄 usercheck.java
字号:
package jspD;
import java.sql.*;
import java.util.*;
public class UserCheck{
private Connection conn;
UserCheck() throws Exception{
String name=request.getParameter(name);
String pwd=request.getParameter(pwd);
String type;
String url="jdbc:microsoft:sqlserver://localhost:1499;DatabaseName=jspDB";
String user="sa";
String password="sa";
try{
<%
String name=request.getParameter("name");
String pwd=request.getParameter("pwd");
String type;
String url="jdbc:microsoft:sqlserver://localhost:1499;DatabaseName=jspDB";
String DBuser="sa";
String password="sa";
// try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn= DriverManager.getConnection(url,DBuser,password);
Statement stmt=conn.createStatement();
String queryStr="select * from users where name='"+name+"'";
ResultSet rs=stmt.executeQuery(queryStr);
// }catch(Exception e){
// e.printStrackTrace();
// }
if(rs==null) {
out.print("<h4 align=center><font color=Red><BLINK>用户不存在</BLINK> <font><h4>");
out.print("<a href='login.jsp' target='_self'>返回</a>");
}else{
while(rs.next()){
out.print("<p>DBname:"+rs.getString(1));
out.print("<p>DBpwd:"+rs.getString(2));
if(pwd==rs.getString(2)){
if(rs.getString(3)=="1"){
type=new String("消费者");
out.print("<h4 align=center>欢迎"+name+"</h4>");
out.print("<h5 align=center><a href='./consumerMain.jsp' target='_self'>继续</a></h5>");
}
else if(rs.getString(3)=="2"){
type=new String("产品供应商");
out.print("<h4 align=center>欢迎"+name+"</h4>");
out.print("<h5 align=center><a href='./producer.jsp' target='_self'>继续</a></h5>");
}
else {
type=new String("管理员");
out.print("<h4 align=center>欢迎"+name+"</h4>");
out.print("<h5 align=center><a href='./admin.jsp' target='_self'>继续</a></h5>");
}
}else{
out.print("<h4 align=center><font color=Red><BLINK>密码错误!请重新输入</BLINK> <font><h4>");
out.print("<a href='./login.jsp' target='_self'>返回</a>");
}
}
}
out.print("<p> name:"+user.getName());
out.print("<p> pwd:"+user.getPwd());
%>
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -