Pages Navigation Menu

Coding is much easier than you think

How to Call Struts2 action from java script

 

Action Class

 

package com.simplecode.action;
import com.opensymphony.xwork2.ActionSupport;

public class MyAction extends ActionSupport
{
	public String trueCall()
	{
		return SUCCESS;
	}

	public String falseCall()
	{
		return SUCCESS;
	}
}

 
** UPDATE: Struts 2 Complete tutorial now available here.
 

Jsp Pages

 
File : confirmBox.jsp
 

<%@taglib prefix="s" uri="/struts-tags"%>



Calling Action from java script




	


 
Do read :

 
File : truePage.jsp
 




Calling Action from java script


	

True Action

 
File :falsePage.jsp
 




Calling Action from java script


	

False Action

 

Struts.xml

 






  /truePage.jsp



  /falsePage.jsp



 
Recommended Article :

 

Demo

 
On running the application we get
 
javascript in struts 2
 

Here on clicking the submit button, we get a confirm box, in which on clicking “Ok”, trueAction get’s called and on clicking “Cancel”, falseAction gets called.