📄 login.java
字号:
package ch1;
import admin.dbcont;
import java.util.Map;
import com.opensymphony.xwork.ActionContext;
import java.io.*;
import java.sql.*;
import com.opensymphony.xwork.ActionSupport;
public class login extends ActionSupport
{
private String message;
private String name;
private String password;
private ResultSet rs=null;
private String lixbox;
private String strsql;
dbcont db=new dbcont();
public String execute() {
if (name == null || "".equals(name)) {
addFieldError("name","Please Enty Your Name!");
return INPUT;
}
else if (password == null || "".equals(password)) {
addFieldError("password", "Please Enty Your PassWord!");
return INPUT;
}
else if(excute()==false){
addFieldError("flag", "Yor PassWord is Wrong!");
return INPUT;
}
else if("1".equals(lixbox)){
Map session1 = ActionContext.getContext().getSession();
Map session2 = ActionContext.getContext().getSession();
session1.put("name",name);
session2.put("password",password);
return "admin";
}
else if("2".equals(lixbox)){
Map session1 = ActionContext.getContext().getSession();
Map session2 = ActionContext.getContext().getSession();
session1.put("name",name);
session2.put("password",password);
return "user";
}
else{
return INPUT;
}
}
public String admin()
{
if("1".equals(lixbox)){
strsql="Select * from login_admins where userName='" +
name +"' and userPwd='" + password +"'";
}
else if("2".equals(lixbox)){
strsql="Select * from Students where Student_Id='" +
name +"' and StudentPsw='" + password +"'";
}
else{
strsql=null;
}
return strsql;
}
public boolean excute(){
boolean flag=false;
try{
db.getcon();
rs = db.stmt.executeQuery(admin());
if(rs.next()) {
flag = true;
}
rs.close();
db.close();
}
catch(Exception ex){message="错了!!!!!!";}
return flag;
}
public String getMessage() {
return message;
}
public void setLixbox(String lixbox)
{
this.lixbox=lixbox;
}
public String getLixbox()
{
return lixbox;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return this.password;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -