******************************************* 表格*************************
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的属性值不清空