logincheck.java

来自「MM7彩信对接网关示例」· Java 代码 · 共 74 行

JAVA
74
字号
/*
 * Created on 2005-11-30
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.rainbow.util.login;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.hibernate.Session;

import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;
import com.rainbow.util.tools.HibernateUtil;

/**
 * 校验用户登录信息, 如果登录成功, Session里面的IsLogin字段是yes, 否则是no
 * @author Rainbow MMS Platform Leader -- TrWorks
 */
public class LoginCheck extends ActionSupport {

	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	public LoginCheck() {
		super();
	}

	/**
	 * 登陆判断
	 */
	public String execute() throws Exception {
		
		String userName = ServletActionContext.getRequest().getParameter("userName");
		String password = ServletActionContext.getRequest().getParameter("password");
		String role = ServletActionContext.getRequest().getParameter("role");
		
		try{
			Session sess = HibernateUtil.currentSession();
			Connection con = sess.connection();
			PreparedStatement s = con.prepareStatement("select tnId from MMS_TSysPlatformUserManage where tcUserName = ? and tcPassword = ? and tnRole = ?");

			s.setString(1, userName);
			s.setString(2, password);
			s.setInt(3, Integer.parseInt(role));
			
			ResultSet set = s.executeQuery();
			if (set.next()){
				ActionContext.getContext().getSession().put("IsLogin", "yes");
				return SUCCESS;
			}
			else{
				ActionContext.getContext().getSession().put("IsLogin", "no");
				return SUCCESS;
			}
		}
		catch(Exception e1){
			e1.printStackTrace();
		}
		finally{
			HibernateUtil.closeSession();
		}
		
		return ERROR;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?