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.jsp
|
<%@taglib uri="/struts-tags" prefix="s" %> <html> <head><title>Ajax_Anchor_TagExample</title></head> <body><h2>Ajax_Anchor_TagExample</h2><hr> <s:a href="anchorAction.action">Ajax_Anchor_TagExample</s:a> </body> </html> |
2_ AjaxAnchorTag.jsp
|
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sx" uri="/struts-dojo-tags"%> <html> <head><title>Ajax_Anchor_Tag_Example</title><sx:head /> </head> <body><h2>Ajax_Anchor_Tag_Example</h2><hr> <div id="d1">Bharat</div> <s:url id="AjaxTag" value="resultAction.action"></s:url> <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> <constant name="struts.devMode" value="true" /> <package name="roseindia" extends="struts-default"> <action name="anchorAction" class="roseindia.action.AjaxAnchorAction" method="display"> <result name="none">jspPages/AjaxAnchorTag.jsp</result> </action> <action name="resultAction" class="roseindia.action.AjaxAnchorAction"><result name="success">jspPages/DisplayInDivTag.jsp</result> </action></package> </struts> |
5_ DisplayInDivTag.jsp
|
<html> <head> <title>Ajax_Anchor_Tag_Example</title> </head> <body> <h2>Changed Value of div </h2> </body> </html> |
Output

AutocompleteBox.gif

success.gif
