quot; + e.toString());
}
return SKIP_PAGE;
}
@Override
public void release() {
// TODO Auto-generated method stub
super.release();
this.name = "alluser";
this.page = "login.jsp";
}
}
Struts自定义标签--使用表格显示数据(2)
时间:2011-03-20
3.LoginAction.java
package com.test.struts.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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.validator.DynaValidatorForm;
import com.test.Hibernate.UserDAO;
public class LoginAction extends Action {
private UserDAO userDao;
public UserDAO getUserDao() {
return userDao;
}
public void setUserDao(UserDAO userDao) {
this.userDao = userDao;
}
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
DynaValidatorForm loginForm = (DynaValidatorForm) form;
String username = loginForm.getString("username");
String password = loginForm.getString("password");
if (userDao.isValidUser(username, password)) {
List users = userDao.showAll();//在userDao中写操作数据库的方法,其中,showAll()方法是取出数据库中说有数据
request.setAttribute("user", username);
request.getSession().setAttribute("alluser", users);
return mapping.findForward("indexGo");
} else {
return mapping.getInputForward();
}
}
}
4.使用
...
<%@ taglib uri="/WEB-INF/app.tld" prefix="app" %>
...
<app:display page="login.jsp"/>
...
|