B4J Question ServletRequest: how get plain-HTML form parameters

peacemaker

Expert
Licensed User
Longtime User
Hi, All

What's wrong with the code ?
It's plain HTML generated page, without JS (that is unknown for me), just single handler:
B4X:
    srvr.AddHandler("/grabber_settings", "grabber_settings", False)

Single handler app::
Sub Handle(req As ServletRequest, resp As ServletResponse)
    Try
        Log(CRLF & "------------" & CRLF & "Method: " & req.Method)
        Log("ContentType: " & req.ContentType)
        Log(req.GetSession.GetAttributesNames)
        Dim Params As Map = req.ParameterMap
        Log(Params)
        Dim new_url As String = req.GetParameter("RTSP_URL")
        If new_url <> "" Then
            Main.Grabbing = False
            Main.RTSP_URL = new_url
        End If
   
        If Params.ContainsKey("btnStart") Then
            Main.Grabbing = True
        End If
        If Params.ContainsKey("btnStop") Then
            Main.Grabbing = False
        End If
   
        resp.Write("<html><body><form method='POST' action='grabber_settings'>")
        Dim rtsp_form As String = $"Source IP-camera RTSP address: <input type="text" id="RTSP_URL" size = "50" value = "$ & Main.RTSP_URL & "></input>"
        rtsp_form = rtsp_form & $"<button type="Submit">Save URL</button><br>"$
        resp.Write(rtsp_form)
   
        resp.Write("<br>").Write("Grabbing service: " & (IIf(Main.Grabbing, $"<button type="Submit" id="btnStop">STOP</button>"$, _
        $"<button type="Submit" id="btnStart">START !</button>"$)))
        resp.Write("</form></body></html>")
    Catch
        resp.SendError(500, "Server internal error")
    End Try
End Sub


How to get form parameters ? Why method is wrongly got ?
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
SOLVED: id of form element was used in JS code, for plain HTML "name" identification is needed.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…