In this example, we will introduce you to how to change value of div tag using Ajax in struts, without reloading page.
1-index.jsp
<%@ page contentType="text/html; charset=UTF-8"%> <%@taglib uri="/struts-tags" prefix="s" %> <%@taglib uri="/struts-dojo-tags" prefix="sx" %> <html> <head><title>Struts Ajax example</title><sx:head /></head> <body><h1>Struts Ajax example......</h1><hr/> <sx:div id="displayImage">Hello friends.................</sx:div> <s:url id="imagePage" value="imageAction.action"></s:url> <sx:a href="%{imagePage}" targets="displayImage">Change Content of Ajax div tag. </sx:a></body> </html> |
2_ AjaxAction.java
package roseindia; import com.opensymphony.xwork2.ActionSupport; public class AjaxAction extends ActionSupport{ public String execute() throws Exception { // TODO Auto-generated method stub return SUCCESS; } } |
3_ struts.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <constant name="struts.devMode" value="true" /> <package name="roseindia" extends="struts-default"> <action name="indexpage"> <result >index.jsp</result> </action> <action name="imageAction" class="roseindia.AjaxAction"> <result name="success">hello.jsp</result> </action> </package> </struts> |
4_ hello.java
<img alt="Image not display" src="images/roseindialogo.jpeg"> New content of ajax div tag |
Output
Advertisements
Ads
Ads