簡體   English   中英

如何在Struts 2中的JSP中顯示標簽內訪問請求屬性

[英]How to access request attribute inside display tag in JSP in struts 2

我在動作類中設置了一個arraylist,如下所示

    public class Student {

        public String execute()  {

        List students_list = new ArrayList(); 

        //business service that fetches students 
        students_list = studentService.getStudents(); 

        request.setAttribute("StudentList", students_list);

        return "listStudents";
     } 
}

在我的jsp中,我正在如下訪問

<%@ taglib prefix="s" uri="/struts-tags"%>

<%@ taglib uri="/WEB-INF/displaytag-12.tld" prefix="display" %>

    <display:table uid= "studentTable" name="%{#request.StudentList}" border="0" cellpadding="0" cellspacing="1" styleClass="data" width="100%" export="true" requestURI="listStudents.action">

        <display:setProperty name="basic.empty.showtable" value="true" />   

        <display:setProperty name="basic.show.StudentList" value="false" />

        <display:setProperty name="css.th.sortable" value="centbold" />

        <display:setProperty name="css.th.sorted" value="centbold" />

        <display:setProperty name="export.excel.filename" value="StudentList.xls" />

        <display:setProperty name="export.banner">
            ...........................................
            ...........................................

    </display:table>

struts.xml

<action name="listStudents" class="com.students.action.Student">
    <result name="listStudents">/jsp/listStudents.jsp</result>
</action>

我也將displaytag-1.0.jar添加到項目的WEB-INF / lib文件夾中。

該表未顯示在jsp(空白jsp)中。
我可以知道如何解決這個問題嗎?
提前致謝

嘗試更改uri

<%@ taglib uri="http://displaytag.sf.net" prefix="display"%> 

您需要這些jar文件

  1. commons-beanutils-1.7.0.jar
  2. commons-collections-3.1.jar
  3. commons-lang-2.3.jar
  4. displaytag-1.2.jar
  5. itext-1.3.jar
  6. jcl104-over-slf4j-1.4.2.jar
  7. log4j-1.2.13.jar
  8. poi-3.2-FINAL.jar
  9. slf4j-api-1.4.2.jar
  10. slf4j-log4j12-1.4.2.jar

使用此CSS

樣式

table {     border: 1px solid #666;     width: 80%;     margin: 20px 0 20px 0 !important; } th,td {     padding: 2px 4px 2px 4px !important;    text-align: left;   vertical-align: top; } thead tr {   background-color: #999999; } th.sorted {    background-color: #CCCCCC; } th a,th a:visited {    color: black; } th a:hover {    text-decoration: underline;     color: black; } th.sorted a,th.sortable a {     background-position: right;     display: block;     width: 100%; } tr.odd {     background-color: #fff } tr.tableRowEven,tr.even {  background-color: #CCCCCC } .group-1 { font-weight:bold; padding-bottom:10px; border-top:1px solid black; } .group-2 { font-style:italic; border-top: 1px solid black; } .grouped-table tr.even { background-color: #fff; } .grouped-table tr.odd { background-color: #fff; }

我發現struts 2框架不支持displaytag-1.0.jar。
解決方案

  • 添加最新的jar-displaytag-1.2.jar。 該jar依賴於commons-lang-2.x jar,因此該jar也應位於WEB-INF / lib文件夾中。

  • 使用JSP 2.0和displaytag-1.2.jar,在WEB-INF文件夾中不需要displaytag-12.tld。

  • 在JSP中,包括<%@ taglib uri =“ http://displaytag.sf.net” prefix =“ display”%>
  • 要訪問展示廣告代碼中的請求屬性,只需使用

    <display:table uid= "studentTable" name="StudentList">
    其中“ StudentList”是在操作類中設置的請求屬性。

  • 如果顯示表需要導出到CSV | XML | EXCEL,則將displaytag-export-poi-1.2.jar添加到lib文件夾中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM