B4J Question [SOLVED] ServerHelloWorld

Jones Hone

Active Member
Licensed User
Longtime User
I test this( ServerHelloWorld example) sample web server program.
Execute the above url, The CreateHtml.exe can create abc.html file,
How do I show the abc.htm file to the client browser?
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    mreq = req
    mresp = resp
    If req.GetParameter("create")="yes" Then
        Dim js As Shell
        Dim params As List: params.Initialize
        params.Add("filename=abc.html")
        js.Initialize("js","c:\test\CreateHtml.exe", params)
        js.WorkingDirectory = File.DirApp
        js.RunWithOutputEvents(-1)
        Do While ProcessExists("CreateHtml.exe")=True
            'Wait for the program to finish running
        Loop
        'The CreateHtml.exe can create abc.html file,
        'How do I show the abc.htm file to the client?
        '???????????????
    End If
End Sub

Sub ProcessExists(ExeName As String) As Boolean 
    Dim Result As ShellSyncResult
    Dim Sh As Shell
    Sh.InitializeDoNotHandleQuotes("", "tasklist", Null)
    Result = Sh.RunSynchronous(5000)
    Return Result.StdOut.ToLowerCase.Contains(ExeName.ToLowerCase)
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Do While ProcessExists("CreateHtml.exe")=True
            'Wait for the program to finish running
        Loop
No. No. No. Don't create busy loops.
In this case it will be simplest to use Shell.RunSynchronous.

If the html doesn't depend on any other files then read it and write it with resp.Write.
If there are multiple files then put the files in the www folder and redirect the client with resp.SendRedirect.
 
Upvote 0

Jones Hone

Active Member
Licensed User
Longtime User
The way you taught me (Shell.RunSynchronous & resp.SendRedirect) works great.
Erel, Thank you very much.
 
Upvote 0
Top