这是我的问题:
我使用Liferay 6.2,使用Struts2
我想使用DisplayTag进行分页,但表格不会出现,Liferay会向我显示此消息" 未找到任何内容。"
我需要在HTML表格中显示3名学生:
我将所有代码(下面的代码)放在一个简单而经典的动态Web项目中#34;有了Tomcat7,我可以看到我的3个学生。
但是在这里,有了Liferay,我已经收到了消息" 无法显示。"
Web.xml:
<web-app [...]>
<display-name>HelloStruts</display-name>
<display-name>Struts 2 Web Application</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Struts.xml:
<struts>
<constant name="struts.devMode" value="true" />
<package namespace="/view" extends="struts-portlet-default" name="view">
<action name="viewDisplayTags" class="com.displaytags.StudentAction" method="fetchStudentList">
<result name="success">/html/displaytags/viewDisplayTags.jsp</result>
</action>
</package>
</struts>
StudentAction.java:
public class StudentAction extends ActionSupport {
private List<StudentBean> students = new ArrayList<StudentBean>();
public String fetchStudentList() {
students.add(new StudentBean("o7bb002", "Ajay"));
students.add(new StudentBean("o7bc055", "Mohiadeen"));
students.add(new StudentBean("o7bc074", "Sriram Ganesh"));
return SUCCESS;
}
public List<StudentBean> getStudents() {
return students;
}
public void setStudents(List<StudentBean> students) {
this.students = students;
}
}
StudentBean.java
public class StudentBean {
private String rollNo;
private String studentName;
public StudentBean(String rollNo, String studentName) {
this.rollNo = rollNo;
this.studentName = studentName;
}
public String getRollNo() {
return rollNo;
}
public void setRollNo(String rollNo) {
this.rollNo = rollNo;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
}
viewDisplayTags.jsp
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ include file="/html/init.jsp" %>
<%@ include file="headerDisplayTags.jspf" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net"%>
<s:hidden name="studentsHiddenList" value="%{students}" />
<display:table name="students">
<display:column property="rollNo" title="Roll No" sortable="true"></display:column>
<display:column property="studentName" title="Student Name" sortable="true" ></display:column>
</display:table>
这很奇怪,因为&#34;隐藏&#34;的内容(&#34; viewDisplayTags.jsp &#34;)我可以看到我的3名学生......学生列表从Java类传输到JSP
谢谢!
答案 0 :(得分:0)
我终于找到了答案:
列表&#34; 学生&#34;没有&#34;请求&#34; &#34;&#34;中的属性 class 和 requestURI 没有正确设置
StudentAction.java:
public class StudentAction extends ActionSupport {
private List<StudentBean> students = new ArrayList<StudentBean>();
public String fetchStudentList() {
students.add(new StudentBean("o7bb002", "Ajay"));
students.add(new StudentBean("o7bc055", "Mohiadeen"));
students.add(new StudentBean("o7bc074", "Sriram Ganesh"));
Map request = (Map) ActionContext.getContext().get("request");
request.put("students",students);
return SUCCESS;
}
public List<StudentBean> getStudents() {
return students;
}
public void setStudents(List<StudentBean> students) {
this.students = students;
}
}
viewDisplayTags.jsp
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ include file="/html/init.jsp" %>
<%@ include file="headerDisplayTags.jspf" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net"%>
<s:hidden name="studentsHiddenList" value="%{students}" />
<display:table name="students" class="StudentAction" requestURI="/viewDisplayTags.jsp">
<display:column property="rollNo" title="Roll No" sortable="true"></display:column>
<display:column property="studentName" title="Student Name" sortable="true" ></display:column>
</display:table>