B4J Question Ignore mreq / mresp globals in server handler class

avalle

Active Member
Licensed User
Longtime User
I see in the server guide and in most server examples that
Handler class:
Private mreq As ServletRequest        'ignore
comes with this "ignore" comment.
What does ignore mean here?

The Handle Sub typically contains the following:
Sub Handle:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    mreq = req
    mresp = resp
Is there any difference in referring to mreq vs. req or mresp vs. resp?

If I need to call a Sub within the same Handler class, which needs to work on the response, is it ok to use the mresp global within the Sub, or instead should I ignore mresp and pass resp as a parameter of the Sub?
Option 1:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    mreq = req
    mresp = resp
    MyPrivateSub
End Sub

Sub MyPrivateSub ()
    mresp.write("Hello!")
End Sub

Option 2:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    mreq = req
    mresp = resp
    MyPrivateSub(resp)
End Sub

Sub MyPrivateSub (response As ServletResponse)
    response.write("Hello!")
End Sub

Which one is correct: Option 1 or 2?
And if Option 1 is fine, why ignore it?
 

avalle

Active Member
Licensed User
Longtime User
Thanks Erel, I didn't know the purpose of the 'ignore comment is to suppress the compiler warning for unused variables.
So option 1 is ok, great!
 
Upvote 0
Top