struts2标签迭代显示list中储存对象的属性值

action:(注意登陆方法中的代码)

package cn.net.xsoft.action;
import java.util.List;

import cn.net.xsoft.bo.ArticleBO;
import cn.net.xsoft.bo.ArticleTypeBO;
import cn.net.xsoft.bo.LoginBO;
import cn.net.xsoft.po.Article;
import cn.net.xsoft.po.ArticleType;
import cn.net.xsoft.po.User;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * action
 * @author H
 *
 */
public class LoginAction extends ActionSupport{
	
	private ArticleBO articleBO;
	
	private ArticleTypeBO articleTypeBO;
	
	private LoginBO loginBO;
	
	private String password;
	
	private String username;
	
	public ArticleBO getArticleBO() {
		return articleBO;
	}

	public void setArticleBO(ArticleBO articleBO) {
		this.articleBO = articleBO;
	}

	public ArticleTypeBO getArticleTypeBO() {
		return articleTypeBO;
	}

	public LoginBO getLoginBO() {
		return loginBO;
	}

	public String getPassWord() {
		return password;
	}

	public String getUserName() {
		return username;
	}

	//登陆
	public String login() throws Exception {

		 User user = loginBO.checkLogin(username, password);
		 System.out.println(user);
		 if(user!=null){
		
			/**
			 * 为了显示登陆之后的博文类别
			 * 
			 */
			List type_list = articleTypeBO.searchArticleType(); //type_list已经存储了ArticleType对象
			System.out.println(type_list);
			System.out.println(type_list.get(0).getTypeName());
			ActionContext.getContext().getSession().put("type_list",type_list); //存储在session中
		
			/**
			 * 为了显示登陆之后的全部博文
			 */
			
			List
article_list = articleBO.searchArticle(); //article_list中已经储存了Article对象 System.out.println(article_list); ActionContext.getContext().getSession().put("article_list", article_list); //存储在session中 return this.SUCCESS; } return this.ERROR; } //注销 public String logout() throws Exception { ActionContext.getContext().getSession().remove("usr"); ActionContext.getContext().getSession().clear(); return this.SUCCESS; } public void setArticleTypeBO(ArticleTypeBO articleTypeBO) { this.articleTypeBO = articleTypeBO; } public void setLoginBO(LoginBO loginBO) { this.loginBO = loginBO; } public void setPassWord(String passWord) { this.password = passWord; } public void setUserName(String userName) { this.username = userName; } }


jsp:(显示)

<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>




Insert title here








value="#session.type_list" status="id" id="id" >
value="#session.article_list" status="id" id="id" >


效果图:

struts2标签迭代显示list中储存对象的属性值_第1张图片



你可能感兴趣的:(SSH)