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<ArticleType> 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> 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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<!--网页头部分-->

<!--<s:include value="head_top.jsp"></s:include>-->


<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">

 <table width="291" border="0" align="center" cellpadding="0" cellspacing="0">
<s:iterator value="#session.type_list" status="id" id="id"  >
    
       <td>
            <s:a href="#" class="button icon-gear" title="查看详情"><s:property value="typeName" /></s:a>
       </td>
   
</s:iterator>	
</table>

 <table width="380" border="0" align="center">
 <s:iterator value="#session.article_list" status="id" id="id"  >
    <tr>
       <tr>
           <td>
        <s:a href="#" class="button icon-gear" title="查看详情"><s:property value="title" /></s:a>
           </td>
        </tr>
        
        
        <tr>
           <td>
        <s:a href="#" class="button icon-gear" title="查看详情"><s:property value="content" /></s:a>
           </td>
        </tr>
    </tr>
</s:iterator>	
</table>

</table>




<!--网页尾部分-->
<s:include value="head_down.jsp"></s:include>





</body>
</html>


效果图:




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值