⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginaction.java

📁 A network chatroom,a a project of database ,is highlighted by my teacher,which using the newest tech
💻 JAVA
字号:
package org.yeeku.action;

import com.opensymphony.xwork2.ActionContext;
import java.util.*;
import org.yeeku.action.base.BaseAction;

import java.util.Vector;
import org.apache.struts2.ServletActionContext;
import org.yeeku.service.ChatMessage;
import javax.servlet.ServletContext;
public class LoginAction extends BaseAction
{
	private String user;
	private String pass;
	private String vercode;


	@Override
	public String execute() throws Exception
	{
		Map session = ActionContext.getContext().getSession();
        String ver2 = (String )session.get("rand");
        if (vercode.equals(ver2))
        {
            int userId = mgr.loginValid(user , pass);
            if (userId > 0)
            {
                session.put("userId" , userId);
                session.put("username",user);
                Calendar ca = Calendar.getInstance();
                int m=ca.get(Calendar.MINUTE);
                ServletContext m_application=ServletActionContext.getServletContext();
                if(m_application.getAttribute(user)==null){
			if(m_application.getAttribute("chatUser")==null){//初始化用户列表
				Vector chatUser=new Vector();
				chatUser.addElement(user);
				m_application.setAttribute("chatUser",chatUser);
			}
			else{
		Vector tempVector=(Vector)m_application.getAttribute("chatUser");
				tempVector.addElement(user);
				m_application.setAttribute("chatUser",tempVector);
			}
                }
		m_application.setAttribute(user,Integer.toString(m));
                String msg="[系统消息]"+user+"上线了";  
                ChatMessage addmessage= new ChatMessage();
                addmessage.addToChatmsg(msg,m_application);
                return SUCCESS;
            }
            else
            {
                addActionError("用户名/密码不匹配");
            }
        }
        else
        {
			addActionError("验证码不匹配,请重新输入");
        }
		return "failure";
	}

	public void setUser(String user)
	{
		this.user = user;
	}
	public String getUser()
	{
		 return this.user;
	}

	public void setPass(String pass)
	{
		this.pass = pass;
	}
	public String getPass()
	{
		 return this.pass;
	}

	public void setVercode(String vercode)
	{
		this.vercode = vercode;
	}
	public String getVercode()
	{
		 return this.vercode;
	}
}

⌨️ 快捷键说明

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