日期:2014-05-16 浏览次数:20704 次
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="ajaxdemo" extends="struts-default"> <action name="UserListingAction" class="ajaxdemo.action.UserListingAction"> <result>/userlisting.jsp</result> </action> <action name="UserDetailAction" class="ajaxdemo.action.UserDetailAction"> <result>/userdetail.jsp</result> </action> </package> </struts>
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <s:head theme="ajax"/> </head> <script> function show_user_details(id) { document.frm_user.userid.value = id; dojo.event.topic.publish("show_detail"); } </script> <body> <s:form id="frm_user" name="frm_user"> <h1>User Listing</h1> <s:if test="userList.size > 0"> <table border="1"> <s:iterator value="userList"> <tr> <td> <s:a href="#" onclick="javascript:show_user_details('%{id}');return false;"><s:property value="id" /></s:a> </td> <td> <s:property value="name" /> </td> </tr> </s:iterator> </table> </s:if> <s:hidden name="userid"/> <s:url id="d_url" action="UserDetailAction" /> <s:div id="user_details" href="%{d_url}" theme="ajax" listenTopics="show_detail" formId="frm_user" > </s:div> </s:form> </body> </html>
<%@ taglib prefix="s" uri="/struts-tags" %> <h1>User Details</h1> <s:if test="userDetails != null"> <table> <tr><td>Id:</td><td><s:property value="userDetails.id" /></td></tr> <tr><td>Name:</td><td><s:property value="userDetails.name" /></td></tr> <tr><td>Email:</td><td><s:property value="userDetails.email" /></td></tr> <tr><td>Address:</td><td><s:property value="userDetails.address" /></td></tr> </table> </s:if>
package ajaxdemo.action; import ajaxdemo.dto.UserListDTO; import com.opensymphony.xwork2.ActionSupport; import java.util.ArrayList; import j