单击链接获取列表并使用struts中的display标签显示

时间:2010-04-09 06:41:25

标签: java jsp struts displaytag

我点击链接,我想从数据库中获取整个列表并使用display tag显示。我在使用display tag(displaytag)时没有任何问题。但是我没有得到如何获得单击struts中超链接的完整列表。

当点击链接时,我正在移动到一个jsp并且有一个显示标签,我必须显示列表,但是我怎么能得到它?

1 个答案:

答案 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.dostruts-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>标记,它将为您呈现锚标记。