我点击链接,我想从数据库中获取整个列表并使用display tag显示。我在使用display tag(displaytag)时没有任何问题。但是我没有得到如何获得单击struts中超链接的完整列表。
当点击链接时,我正在移动到一个jsp并且有一个显示标签,我必须显示列表,但是我怎么能得到它?
答案 0 :(得分:0)
使用Ajax,因为displaytag不支持ajax,所以不可能。这是一种做法(如果我明白你想做什么)。
onclick事件处理程序将指向您的Struts操作。然后,该操作将从数据库中获取所有信息,填充列表,将其存储在request.setAttribute
请求中,并将转发返回到jsp页面。
在JSP页面中,使用displaytag迭代列表,并使用bean:write
标记显示值。
E.g。
这是使用EL(表达式语言)指向Struts Action页面的锚标记的示例。
<a href="${pageContext.request.contextPath}/myAction.do?command=DoSomeCommand&userId=<bean:write name="user" property="id" />"><bean:message key="label.my_link" /></a>
/myAction.do
在struts-config.xml
文件中声明为
<action path="/myAction" type="org.apache.struts.action.MyAction" scope="request" parameter="command">
</action>
如果你想使用锚onclick
事件做类似的事情:
<a onclick="window.location.href='${pageContext.request.contextPath}/myAction.do?command=DoSomeCommand&userId=<bean:write name="user" property="id" />'" href="#"></a>
其中${pageContext.request.contextPath}
表示<%= request.getContextPath() %>
或者,使用struts <html:link>
标记,它将为您呈现锚标记。