JAVA

java数据交互(四)

2017-02-23  本文已影响9人  冰点雨

1.jsp页面之间的简单数据传递
不管是A页面向B页面传数据,还是B页面向A页面传数据,只需要在传递页面设置属性,被传递页面之间取值就好。
A页面的jsp

 <form id="form1" method="post">
        <input type="button" onclick="jumpPage()" value="跳转页面">
  </form>

function jumpPage() {
            $("#form1").attr("action", "/personAction!jumpPage.do");
            $("#form1").submit();
        }

A页面对应的action

@Action(value = "personAction", results = { @Result(name = "index", location = "/app/test/testPersonDetail.jsp")})

//页面间的跳转   直接return “页面路径”;
//页面间的传值   不管是从前往后传,还是从后往前传,
// 跳转的界面  只管设置属性 request.setAttribute("介","值");
//    被跳转的界面通过  ${介}取值
    public String jumpPage()
    {
        request.setAttribute("AProperty","A页面传的值");
        return "index";
    }

B页面的jsp

<p>新节目${AProperty}</p

B页面


QQ图片20170301104424.png

A页面


QQ图片20170301104454.png

2.jsp页面之间传递对象集合
A页面的jsp

 <form id="form1" method="post">
        <input type="button" onclick="jumpPageToData()" value="跳转页面并传对象集合">
  </form>

 function jumpPageToData() {
            $("#form1").attr("action", "/personAction!jumpPageToData.do");
            $("#form1").submit();
        }

A页面对应的action

@Action(value = "personAction", results = { @Result(name = "index", location = "/app/test/testPersonDetail.jsp")})

 public String jumpPageToData()
    {
        List<TestPerson> list = testService.getAllPersonlist();
//        跳转页面的时候设置属性
        request.setAttribute("list",list);
        return "index";
    }

B页面的jsp

//必须进行引用,不然c标签使用不了
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<table id="dg" title="我的用户" class="easyui-datagrid" style="width: 680px;height:500px" url="" toolbar="#toolbar"
       rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr class="tbtr">
        <th field="name" width="70">姓名</th>
        <th field="age" width="70">年龄</th>
        <th field="address" width="70">地址</th>
        <th field="company" width="120">公司</th>
        <th field="job" width="70">职业</th>
        <th field="salary" width="70">工资</th>
        <th field="addTime" width="130">添加时间</th>
    </tr>
    </thead>

<%--从上一个页面接收的对象集合,使用C标签循环list,将数据添加到table中--%>
    <c:forEach items="${list}" var="t">
        <tr>
            <td>${t.name}</td>
            <td>${t.age}</td>
            <td>${t.address}</td>
            <td>${t.company}</td>
            <td>${t.job}</td>
            <td>${t.salary}</td>
            <td>${t.addTime}</td>
        </tr>
    </c:forEach>
</table>
QQ图片20170301104606.png
上一篇 下一篇

猜你喜欢

热点阅读