开发者

onclick of a link get the list and display using display tag in struts

开发者 https://www.devze.com 2022-12-26 11:11 出处:网络
I have link on click of which i want to get the entire list from database and display using display tag.I don\'t have any problem in using display tag (displaytag).,But i am not getting how would get

I have link on click of which i want to get the entire list from database and display using display tag.I don't have any problem in using display tag (displaytag).,But i am not getting how would get the complete list on click of a hyperlink in struts.

As on clicking the link i am moving to a jsp and having a display tag where i have to dispaly the list开发者_如何转开发,But how would i get it?


With Ajax, it's not possible since displaytag has no support for ajax. Here is a way of doing this (if I understood what you want to do).

The onclick event handler will point to your Struts action. The action will then get all information from database, populate the list, store it in request.setAttribute request and return a forward to a jsp page.

From the JSP page, use displaytag to iterate through the list, and display the value using bean:write tag.


E.g.

This is an example of an anchor tag that uses EL (expression language) pointing to a Struts Action page.

<a href="${pageContext.request.contextPath}/myAction.do?command=DoSomeCommand&userId=<bean:write name="user" property="id" />"><bean:message key="label.my_link" /></a>

The /myAction.do is declared in struts-config.xml file as

<action path="/myAction" type="org.apache.struts.action.MyAction" scope="request"  parameter="command">

</action>

if you want to use the anchor onclick event do something like this:

<a onclick="window.location.href='${pageContext.request.contextPath}/myAction.do?command=DoSomeCommand&userId=<bean:write name="user" property="id" />'" href="#"></a>

where ${pageContext.request.contextPath} means <%= request.getContextPath() %>

alternatively, use the struts <html:link> tag and it'll render an anchor tag for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消