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

📄 logaction.java

📁 基于Struts+Spring+Hibernate的航空票务系统
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yc.struts.action;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.yc.dao.LogUserDao;
import com.yc.model.Users;
import com.yc.struts.form.LogUserForm;

/** 
 * MyEclipse Struts
 * Creation date: 01-07-2009
 * 
 * XDoclet definition:
 * @struts.action path="/log" name="logUserForm" scope="request" validate="true"
 */
public class LogAction extends Action {
	
	private LogUserDao userdao;
	
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws UnsupportedEncodingException 
	 */
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
		LogUserForm logUserForm = (LogUserForm) form;// TODO Auto-generated method stub
		String path=servlet.getServletContext().getRealPath("/src/applicationContext.xml");
		//从session中读取path属性
		String rq=(String)request.getSession().getAttribute("path");
		if(rq!=null)
		{
			request.getSession().removeAttribute("path");
		}
		request.getSession().setAttribute("path", path);
		
		String username=(String)logUserForm.getUserid();
		String password=(String)logUserForm.getPassword();
		username=new String(username.getBytes("ISO-8859-1"),"GB2312");
		password=new String(password.getBytes("ISO-8859-1"),"GB2312");
		
		HttpSession session=request.getSession();
		
		ActionMessages errors=new ActionMessages();
		
		String tmp=null;
		
		if(userdao.IsUserValid(username, password))
		{
			Users u=(Users)userdao.getUser(username, password);
			if(u!=null)
			{
				tmp=(String)session.getAttribute("curr_user");
				if(tmp==null)
				{
					session.setAttribute("curr_id", u.getId());
					session.setAttribute("curr_user",username);
				}
				else
				{
					session.removeAttribute("curr_id");
					session.removeAttribute("curr_user");
					session.setAttribute("curr_id", u.getId());
					session.setAttribute("curr_user",username);
				}
				return (mapping.findForward("login"));
			}
			else
			{
				errors.add("fail",new ActionMessage("user login fail"));
				saveErrors(request,errors);
				return (mapping.getInputForward());
			}
		}
		else
		{
			errors.add("fail",new ActionMessage("valid fail"));
			saveErrors(request,errors);
			return (mapping.getInputForward());
		}
	}
	
	public LogUserDao getUserdao()
	{
		return this.userdao;
	}
	
	public void setUserdao(LogUserDao userdao)
	{
		this.userdao=userdao;
	}
	
}

⌨️ 快捷键说明

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