Displaytag in included page

不打扰是莪最后的温柔 提交于 2019-12-13 06:17:34

问题


I would like to use displaytag in an included page but I have difficulties. I have got a main page which includes a header jspf, a menu jspf and an other jspf depending on the selected menu (on menu.jspf)

main.jspf

<html><body>
<table border="0">
  <tr>
     <td colspan="2"><s:include value="header.jspf"/></td>
  </tr>
  <tr>
     <td><s:include value="menu.jspf"/></td>
     <td><s:include value="%{page}"/></td>
  </tr>
</table>
</body></html>

the "other" jspf (I change the value of 'page' variable in a Struts2 action)

<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>
<%@ taglib prefix="s" uri="/struts-tags" %> 
<html>
<link rel="stylesheet" href="./css/screen.css" type="text/css"/>
<link rel="stylesheet" href="./css/displaytag.css" type="text/css"/>
<body>

   <display:table name="${usageList}" pagesize="2" requestURI="menu_admin_freq.action" sort="list" class="mars">
      <display:column property="nameBackendService" title="BackendService" sortable="true"/>
      <display:column property="frequency" title="Frequency" sortable="true"/>
   </display:table>

</body></html>

As you can see I include a full JSP page which I think is not a good idea... However when I tried to include only a fragment (without the <html> and <body> elements) and put the taglib elements into the main.jsp the displaytag table did not appear... When I removed the <html> and <body> elements and left the taglib one then I could see a text on the webpage : "<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>"

At the moment I have got a working solution (by using <html>, <body> a <%@ taglib> elements in the page that must be included) but I think mine is quite a bad design pattern. How should I sort out this? Thanks, Viktor


回答1:


Struts2 <s:include> tag includes a result of servlet or a JSP page. If you want to include JSP fragments use JSP include directive <%@ include file="..." %>.

For using <s:include> tag rename your pages to .jsp and put only taglib directive (w/o <html>, <body>) along with your table to the included pages.




回答2:


You should use

<jsp:include page="mySnippet.jsp"/>

where mySnippet.jsp is a partial Jsp, with no DTD, no head, no body, and only the HTML fragment you need.

When needed, declare in it the tag-libraries (struts-tags, etc)...



来源:https://stackoverflow.com/questions/14707167/displaytag-in-included-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!