In this example, you will see the use of Ajax(anchor) tag.
Here, we are changing value of div tag with the help of Ajax anchor tag.
1- index.jspADS_TO_REPLACE_1
<%@taglib uri="/struts-tags" prefix="s" %> <html> <head><title>Ajax_Anchor_TagExample</title></head>ADS_TO_REPLACE_2 <body><h2>Ajax_Anchor_TagExample</h2><hr> <s:a href="anchorAction.action">Ajax_Anchor_TagExample</s:a> </body>ADS_TO_REPLACE_3 </html> |
2_ AjaxAnchorTag.jsp
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sx" uri="/struts-dojo-tags"%>ADS_TO_REPLACE_4 <html> <head><title>Ajax_Anchor_Tag_Example</title><sx:head /> </head>ADS_TO_REPLACE_5 <body><h2>Ajax_Anchor_Tag_Example</h2><hr> <div id="d1">Bharat</div> <s:url id="AjaxTag" value="resultAction.action"></s:url>ADS_TO_REPLACE_6 <sx:a href="%{AjaxTag}" targets="d1">AutoComplete_Tag_Example</sx:a> </body> </html> |
3_ AjaxAnchorAction.java
package roseindia.action; import com.opensymphony.xwork2.ActionSupport; public class AjaxAnchorAction extends ActionSupport { public String execute() throws Exception { return SUCCESS; } public String display() { return NONE; } } |
4_ struts.xml
<struts>ADS_TO_REPLACE_7 <constant name="struts.devMode" value="true" /> <package name="roseindia" extends="struts-default"> <action name="anchorAction" class="roseindia.action.AjaxAnchorAction" method="display">ADS_TO_REPLACE_8 <result name="none">jspPages/AjaxAnchorTag.jsp</result> </action> <action name="resultAction" class="roseindia.action.AjaxAnchorAction">ADS_TO_REPLACE_9<result name="success">jspPages/DisplayInDivTag.jsp</result> </action></package> </struts> |
5_ DisplayInDivTag.jsp
<html>ADS_TO_REPLACE_10 <head> <title>Ajax_Anchor_Tag_Example</title> </head>ADS_TO_REPLACE_11 <body> <h2>Changed Value of div </h2> </body>ADS_TO_REPLACE_12 </html> |
Output
AutocompleteBox.gifADS_TO_REPLACE_13
success.gif
ADS_TO_REPLACE_14
Advertisements
Ads
Ads