1、action
package test.web.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import test.model.NewsModel;
import test.model.PageUtil;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;
public class HelloAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String hello;
private List<NewsModel> newsList = new ArrayList<NewsModel>();
private PageUtil pageUtil = new PageUtil();
public PageUtil getPageUtil() {
return pageUtil;
}
public void setPageUtil(PageUtil pageUtil) {
this.pageUtil = pageUtil;
}
public void setNewsList(List<NewsModel> newsList) {
this.newsList = newsList;
}
public List getNewsList() {
return newsList;
}
public String getHello() {
return hello;
}
public void setHello(String hello) {
this.hello = hello;
}
public String execute() throws Exception{
this.setHello("hello webwork!!!");
return SUCCESS;
}
@SuppressWarnings("unchecked")
public String getFirst() throws Exception{
newsList.add(new NewsModel(1,"newsTilte"));
newsList.add(new NewsModel(2,"newsTilte"));
pageUtil.setItems(newsList);
pageUtil.setPageSize(101);
Map request = (Map)ActionContext.getContext().get("request");
request.put("newsList",newsList);
request.put("pageUtil", pageUtil);
this.setHello("hello first!!!");
return SUCCESS;
}
}
2、jsp视图
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="ww" uri="/webwork" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>hello.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<ww:property value="hello"/><br/>
<ww:iterator value="#request['newsList']" id="book">
<ww:property value="#book.id"/>
<ww:property value="#book.title"/><br/>
</ww:iterator>
<ww:set name="page" value="#request.pageUtil"/>
<ww:iterator value="#page.items" id="news">
<ww:property value="#news.id"/>
<ww:property value="#news.title"/><br/>
</ww:iterator>
</body>
</html>
验证的一视图jsp代码
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="ww" uri="/webwork" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>hello.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form action="add.jhtml" method="post">
title:<input name="newsModel.title" value="<ww:property value="newsModel.title"/>">
<ww:if test="fieldErrors['newsModel.title']!=null">
<ww:property value="fieldErrors['newsModel.title']"/>
</ww:if><br>
<input type="submit" value="提交">
</form>
<ww:form method="post">
<ww:textfield label="Name" name="newsModel.title"/>
<ww:submit value="保存" />
</ww:form>
</body>
</html>
package test.web.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import test.model.NewsModel;
import test.model.PageUtil;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;
public class HelloAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String hello;
private List<NewsModel> newsList = new ArrayList<NewsModel>();
private PageUtil pageUtil = new PageUtil();
public PageUtil getPageUtil() {
return pageUtil;
}
public void setPageUtil(PageUtil pageUtil) {
this.pageUtil = pageUtil;
}
public void setNewsList(List<NewsModel> newsList) {
this.newsList = newsList;
}
public List getNewsList() {
return newsList;
}
public String getHello() {
return hello;
}
public void setHello(String hello) {
this.hello = hello;
}
public String execute() throws Exception{
this.setHello("hello webwork!!!");
return SUCCESS;
}
@SuppressWarnings("unchecked")
public String getFirst() throws Exception{
newsList.add(new NewsModel(1,"newsTilte"));
newsList.add(new NewsModel(2,"newsTilte"));
pageUtil.setItems(newsList);
pageUtil.setPageSize(101);
Map request = (Map)ActionContext.getContext().get("request");
request.put("newsList",newsList);
request.put("pageUtil", pageUtil);
this.setHello("hello first!!!");
return SUCCESS;
}
}
2、jsp视图
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="ww" uri="/webwork" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>hello.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<ww:property value="hello"/><br/>
<ww:iterator value="#request['newsList']" id="book">
<ww:property value="#book.id"/>
<ww:property value="#book.title"/><br/>
</ww:iterator>
<ww:set name="page" value="#request.pageUtil"/>
<ww:iterator value="#page.items" id="news">
<ww:property value="#news.id"/>
<ww:property value="#news.title"/><br/>
</ww:iterator>
</body>
</html>
验证的一视图jsp代码
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="ww" uri="/webwork" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>hello.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form action="add.jhtml" method="post">
title:<input name="newsModel.title" value="<ww:property value="newsModel.title"/>">
<ww:if test="fieldErrors['newsModel.title']!=null">
<ww:property value="fieldErrors['newsModel.title']"/>
</ww:if><br>
<input type="submit" value="提交">
</form>
<ww:form method="post">
<ww:textfield label="Name" name="newsModel.title"/>
<ww:submit value="保存" />
</ww:form>
</body>
</html>