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

📄 homeaction.java

📁 图书商城系统
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.tang.admin.struts.action;

import java.util.ArrayList;

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.ActionErrors;
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 com.tang.admin.foruse.AdminBean;
import com.tang.admin.foruse.UserBean;
import com.tang.admin.foruse.UserDAO;

/** 
 * MyEclipse Struts
 * Creation date: 05-27-2008
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 * @struts.action-forward name="failure" path="/login.jsp"
 * @struts.action-forward name="success" path="/home.jsp"
 */
public class HomeAction extends Action {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		String target = "failure";
		HttpSession session = request.getSession();
		String username = null;
		AdminBean bean = (AdminBean)session.getAttribute("user");
		ActionErrors errors = new ActionErrors();
		if(bean!=null)
		{
			username = bean.getUsername();
		}
		if(username!=null)
		{
			target = "success";
			UserDAO facade = new UserDAO();
			facade.open();
			ArrayList useral = facade.select("select * from users");
			StringBuffer buffer = new StringBuffer("<tr  bgcolor=\"gray\"><th align=\"center\">用户id</th><th align=\"center\">用户名</th><th align=\"center\">删除</a></tr>");
			StringBuffer lists = new StringBuffer();
			for(int i= 0;i<useral.size();i++){
				UserBean userbean = (UserBean)useral.get(i);
				lists.append("<tr><td>"+userbean.getId()+"</td><td>"+userbean.getUsername()+"</td><td><a href=delete.do?uid="+userbean.getId()+" onclick=\"return window.confirm('你确定要删除吗?')\">删除</a></td></tr>");
			}
			request.setAttribute("buffer", buffer);
			request.setAttribute("lists", lists);
		}
		else {
			ActionMessage msg = new ActionMessage("您尚未登录", false);
			errors.add("login", msg);
			request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
			mapping.findForward(target);
		}
		return mapping.findForward(target);
	}
}

⌨️ 快捷键说明

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