Struts jsp 遍历action中的数组

action:

package com;

import java.rmi.RemoteException;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import service.MyServiceStub;
import service.MyServiceStub.Student;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sun.xml.internal.ws.client.RequestContext;

 

public class FindstudentsAction extends ActionSupport {

 public String execute() throws Exception {
      
  //设置远程服务调用地址
  String target = "http://127.0.0.1:8080/axis2/services/MyService";
  //List<Student> list=new ArrayList<Student>();
  try {
   //根据地址构造用户存根
   MyServiceStub stub = new MyServiceStub(target);
   //调用查询学生列表方法
   MyServiceStub.QueryStudentsResponse qsr = stub.queryStudents();
   //返回学生类型对象数组
   Student[] sts = qsr.get_return();
   //将数组输出至前台页面
  
    HttpServletRequest request = ServletActionContext.getRequest();
    request.setAttribute("sts",sts );

   //ActionContext.getContext().getSession().put("sts", sts);
   
  } catch (RemoteException e) {
   e.printStackTrace();
  } catch (Exception e) {
   e.printStackTrace();
  }
  
  return SUCCESS;
 }
}

 jsp:

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s"  uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

  </head>
 
  <body>
   
  <table width="90%" border="1">
            <tr>
             <th>用户id</th>
             <th>用户姓名</th>
             <th>用户住址</th>
             
            </tr>
         <s:iterator value="#request.sts">
          <tr>
           <td align="center"><s:property value="id"/> </td>
           <td align="center"><s:property value="name"/> </td>
           <td align="center"><s:property value="address"/>  </td>
           
          </tr>
         </s:iterator>

</table>


  </body>
</html>

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

public class FindstudentsAction extends ActionSupport {

 public String execute() throws Exception {
      
  //设置远程服务调用地址
  String target = "http://127.0.0.1:8080/axis2/services/MyService";
  //List<Student> list=new ArrayList<Student>();
  try {
   //根据地址构造用户存根
   MyServiceStub stub = new MyServiceStub(target);
   //调用查询学生列表方法
   MyServiceStub.QueryStudentsResponse qsr = stub.queryStudents();
   //返回学生类型对象数组
   Student[] sts = qsr.get_return();
   //将数组输出至前台页面
  
   // HttpServletRequest request = ServletActionContext.getRequest();
  //  request.setAttribute("sts",sts );

   ActionContext.getContext().getSession().put("sts", sts);
   
  } catch (RemoteException e) {
   e.printStackTrace();
  } catch (Exception e) {
   e.printStackTrace();
  }
  
  return SUCCESS;
 }
}

 jsp:

<%@ page language="java" import="java.util.*,java.util.List" pageEncoding="UTF-8"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

  </head>
 
  <body>
   <c:forEach items="${sts}" var="student">
     
       ${student.number} 
     ${student.name} 
     ${student.tel} 
     ${student.address} <br>
</c:forEach>
  </body>
</html>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值