struts2

*******************************************   表格*************************

public class DemoAction extends ActionSupport {

private List<DemoBean> list;

 

public String save(){

list = demoservice.demoSave();

return "next";

}

 

public List<DemoBean> getList() {

return list;

}

 

public void setList(List<DemoBean> list) {

this.list = list;

}

}

 

 

 

 

 

 

<table >

<tr>

<td>name</td>

<td>address</td>

<td>age</td>

</tr>

<s:iterator value="list" id="demoBean">

<tr>

<td align="center"><s:property value="#demoBean.name" /><td/>

<td align="center"><s:property value="#demoBean.address" /><td/>

<td align="center"><s:property value="#demoBean.age" /><td/>

</tr>

</s:iterator>

</table>

*****************************************************************************************

 

 

$.ajax({

url: 'stat.php',

 

type: 'POST',

 

data:{Name:"keyun"},

 

dataType: 'html',

 

timeout: 1000,

 

error: function(){alert('Error loading PHP document');},

 

success: function(result){alert(result);}

 

});

 

 

ajax

 

 

 

 

 

 

$(document).ready(function()

{

$("#sub").click(function(){

window.alert("11");

 $.post("mytestAction_save.action",

 {

   name:"Donald Duck",

   city:"Duckburg"

 },

 function(data,status){

   alert("Data: " + data + "\nStatus: " + status);

 });

});

});

 

HttpServletResponse response = ServletActionContext.getResponse();

String data = "data";

try {

response.getWriter().write(data);       

//response.getWriter().print(json);返回json数据

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

 

 

 // data = eval(data); json数据   POST方法必加,ajax方法自动处理了  

*********************************************************************

 

json

 

public class DemoAction extends ActionSupport {

 

private DemoService demoservice;

private List<DemoBean> list;

private String result;

 

public String save(){

HttpServletResponse response = ServletActionContext.getResponse();

 

List<DemoBean> list = demoservice.demoSave();

JSONArray jsonArray = JSONArray.fromObject(list);      //list 类型的 转json

                                                    //JSONObject json = JSONObject.fromObject(org);   object类型转json

 result = jsonArray.toString();

System.out.println(result);

return SUCCESS;

}

public List<DemoBean> getList() {

return list;

}

 

public void setList(List<DemoBean> list) {

this.list = list;

}

public String getResult() {

return result;

}

 

public void setResult(String result) {

this.result = result;

}

}

 

 

<package name="billQueryAjax" namespace="/" extends="json-default">

<!-- 此处将reslut的值返回给客户端,root的值对应要返回的值的属性result

                      注意:root为固定写法,否则不会把result的值返回给客户端 -->

 

<action name="mytest"  class="demoaction" method="save">

<result type="json">

               

                <param name="root">result</param>

</result>

</action>

</package>

 

 

$(document).ready(function()

{

$("#sub").click(function(){

window.alert("11");

 $.post("mytest.action",

 {

   name:"Donald Duck",

   city:"Duckburg"

 },

 function(result,status){

   alert("Statusdd: " + status);

   window.alert(result);

   var json = eval("("+result+")");

   window.alert(json[1].name);    

 },"json");

});

});

 

**********************************************************************************************

分页

 

 

class user {

   private people po;

   private int money;

 

set..get..

}

 

jsp

<body>

<s:property value="people.name" />    // 等价   ${people.name}

<input type="text" value="${people.name}"/>

<input type="text" value="<s:property value="people.name" />"/>

 

//可做 分页

<a href="#" οnclick="jia('${money + 1}');return false;">   下一页

<a href="#" οnclick="jian('${money - 1}');return false;">   上一页

<a href="#" οnclick="first('${ 1}');return false;">   首页

</body>

 

 

 注: strut2 的action在跳转到 jsp后 ,在从jsp到 action ,action的属性值不清空

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值