DMI.call (JavaScript) to Java servlet

Inserts a new record in table `usermanagement`.`logger`, by running the Javascript isc.DMI.call() that calls the com.wa.usermanagement.server.servlet.logger  and function of it doLogger(); and return through javascript an ok string.

This is an example that shows how to call Java Servlets from JS (Smartclient.)

Java Servlet class

package com.lynvcode.server.servlet;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.lynvcode.server.DBConnection;
public class logger {
    public String doLogger() {

        Connection conn = DBConnection.getConnection();
        int rest;
        String query = "INSERT INTO `logger` (`pk`, `logger`) VALUES (NULL, 'test2');";
        try{
        Statement s = conn.createStatement();
        rest = s.executeUpdate(query);
        if (rest != 0){
            return "test2 ok";
        }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "test2 not ok";
    }

}

Javascript function that calls the servlet.

isc.DMI.call({
           appID: "builtinApplication", // must be under webcontent/apps/builtinApplication.app.xml
           className: "com.lynvcode.server.servlet.logger",
           methodName: "doLogger",
           requestParams: {
               actionURL: "/project_name/project_name/sc/IDACall", //folder under which the IDACall resides in (see logs of catalina or ./startserver.sh thingy output after loading a page in smartgwt
               containsCredentials: true,
               params : {
               }
           },
           callback : function (response, data) {

               if (response.status == isc.RPCResponse.STATUS_SUCCESS) {
                   alert("success");
                    alert(data);
               } else {
                   alert("failed");
               }
           }
       });

builtinApplication.app.xml file under webcontent/app/ or maybe webcontent/shared/app, depends on your server.properties files, check your app folder location.

<Application>
    <rpcBindings>
        <ServerObject ID="logger" className="com.lynvcode.server.servlet.logger">
            <visibleMethods>
                <method name="doLogger"/>
            </visibleMethods>
        </ServerObject>
    </rpcBindings>
</Application>