First of all, I don't know if is possible or not, so I read a lot of posts before asking, how can I call Struts2 action from a JavaScript function?
Examples (Forms):
http://www.simplecodestuffs.com/example-to-call-struts2-action-from-java-script
how to call method in action class in javascript using struts2 framework?
how to redirect to struts action from java script in struts 2?
How to call a method in Struts2 Action Class method with javascript
https://coderanch.com/t/533202/framework/Calling-Action-Class-javaScript-Struts
https://coderanch.com/t/530746/framework/call-method-action-class-Struts
https://coderanch.com/t/551141/framework/call-Struts-action-javascript-function
Thanks for your help.
I put the Struts.xml file where you can see the Struts2 actions and the javascriptFunctions.js that contains de borrarPerfil() where as you can see I need to call Struts2 action
Struts.xml
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="registrar" extends="struts-default">
<action name="registrar" class="registrar.action.Registrar"
method="execute">
<result name="success" type="redirect">/estructura/finRegistro.jsp
</result>
<result name="input" type="dispatcher">/estructura/registro.jsp</result>
</action>
</package>
<package name="tiles" extends="struts-default">
<result-types>
<result-type name="tiles"
class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="*Menu" method="{1}" class="tiles.action.MenuAction">
<result name="inicio" type="tiles">inicio</result>
<result name="quienes" type="tiles">quienes</result>
<result name="servicios" type="tiles">servicios</result>
<result name="donde" type="tiles">donde</result>
<result name="contacto" type="tiles">contacto</result>
</action>
<action name="*Usuario" method="{1}" class="tiles.action.UsuarioAction">
<result name="perfil" type="tiles">perfil</result>
<result name="agenda" type="tiles">agenda</result>
<result name="servicios" type="tiles">mservicios</result>
<result name="consulta" type="tiles">consulta</result>
<result name="ayuda" type="tiles">ayuda</result>
</action>
</package>
<package name="contacto" extends="tiles">
<action name="validar" class="validar.action.Validar" method="execute">
<result name="success" type="tiles">finContacto</result>
<result name="input" type="tiles">contacto</result>
</action>
</package>
<package name="login" extends="tiles">
<interceptors>
<interceptor name="loginInterceptor" class="login.interceptor.LoginInterceptor">
</interceptor>
<interceptor-stack name="loginStack">
<interceptor-ref name="loginInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<!-- login action -->
<action name="login" class="login.action.Login">
<result name="input" type="tiles">inicio</result>
<result name="success" type="tiles">usuarioLayout</result>
</action>
<!-- logout action -->
<action name="logout" class="login.action.Login" method="logout">
<result name="success" type="tiles">inicio</result>
</action>
</package>
<package name="modificar" extends="tiles">
<action name="modificar" class="modificar.action.Modificar" method="execute">
<result name="success" type="tiles">finModificar</result>
<result name="input" type="tiles">menuLayout</result>
</action>
</package>
<package name="borrar" extends="titles">
<action name="borrar" class="borrar.action.Borrar">
<result name="success" type="tiles">inicio"</result>
</action>
</package>
javascriptFunctions.js
function borrarPerfil() {
if(confirm("Are you sure to delete this profile?")){
alert("deleted");
//CALL STRUTS2 ACTION borrar
} else {
alert("no paso nada");
//CALL STRUTS2 ACTION logout
}
}