我想将分页应用于我的 struts2 Web 应用程序。当用户登录时,我将他们重定向到主页,我想在主页上使用display
标签显示所有用户。
我已经完成了研究并最终将其集成到我的 struts2 中,但是当我登录后运行代码时,它会显示消息Nothing found to display
。
当我在 struts1.3 中以该站点为例进行了相同的操作时,它就可以工作了。我已将以下 JAR 文件复制到我的lib
文件夹中:
commons-logging.jar
commons-lang.jar
commons-collections.jar
commons-beanutils.jar
displaytag-1.2.jar
我也复制displaytag.tld
到struts-2.17.dtd
了我的web-inf
文件夹中。
下面是我的代码:
我的个人资料.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
</head>
<body>
<div id="wrapper">
<div id="steps">
<fieldset class="step">
<legend>Profile
</legend>
<display:table id="data" name="list" requestURI="/display.action" pagesize="1" >
<display:column sortable="true">
<p>
<label for="username">User Name</label>
<input id="username" name="username" value="<s:property value="firstName" />" disabled="disabled"/>
</p>
<p>
<label for="email">Father Name</label>
<input id="email" name="email" value="<s:property value="lastName"/>" disabled="disabled" />
</p>
<p>
<label for="password">Age</label>
<input name="password" value="<s:property value="dob"/>" disabled="disabled"/>
</p>
<p>
<label for="address">Address</label>
<input name="address" value="<s:property value="emailID"/>" disabled="disabled"/>
</p>
</fieldset>
</div>
</display:column>
</display:table>
</div>
</div>
</body>
</html>
Struts.xml
<action name="display" class="com.java.action.SearchAction">
<result name="success">/profile.jsp</result>
<result name="errror">/error.jsp</result>
</action>
SearchAction.java
private ArrayList<UserBean> list=new ArrayList<UserBean>();
//setter getter
public String execute()
{
UserBean rt=new UserBean();
SearchDB user=new SearchDB();
this.setList(user.search(gender,age_min,age_max,religion,caste,photo_display));
return SUCCESS;
}
用户Bean.java
public class UserBean {
private String emailID;
private String userName;
private String gender;
private String dob;
private String firstName;
private String lastName;
private int Id;
//setter and getter
}
SearchDB.java
//code to get records. their is no problem here because it is taking records out from db fine.
我不确定,但我的猜测是requestURI
和 name 属性,displaytag
因为在上面链接的示例中,他们使用name="sessionScope.UserForm.userList"
. 有人能告诉我我哪里做错了吗?