在Struts中使用displaytag标签的排序/分页数据(二)

2014-11-24 09:56:26 · 作者: · 浏览: 1
org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class UserAction extends Action {

private final static String SUCCESS = "success";

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
UserForm userForm = (UserForm) form;
ForbesData actorData = new ForbesData();
userForm.setForbesList(actorData.loadData());
return mapping.findForward(SUCCESS);
}

}
第3步:创建JSP,struts-config.xml和web.xml文件
在WebContent文件夹和struts-config.xml和web.xml中的WebContent / WEB-INF文件夹中创建index.jsp和user.jsp。

的struts-displaytag标签的网页,XML,JSP
复制以下内容转换成相应的文件。

index.jsp的
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
//原文由 www.software8.co 站长百科译
<jsp:forward page="userAction.do"/>
user.jsp
"http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://displaytag.sf.net" prefix="display" %>



The World's Billionaires 2009



The World's Billionaires 2009 - Forbes List


name="sessionScope.UserForm.forbesList"
requestURI="/userAction.do" pagesize="10" >



sortable="true" />



struts-config.xml中
< xml version="1.0" encoding="UTF-8" >

"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">




type="net.viralpatel.struts.displaytag.UserForm"/>







scope="session" type="net.viralpatel.struts.displaytag.UserAction">








web.xml中
< xml version="1.0" encoding="UTF-8" >
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

action

org.apache.struts.action.ActionServlet


config
/WEB-INF/struts-config.xml


debug
2


detail
2

2


action
*.do


30


index.jsp


第4步:执行项目
我们已经完成了这个项目。现在执行的项目在Eclipse中创建一个WAR文件,并在Tomcat上运行。

Struts的displaytag标签的例子