B4J Question [Web App] Get current URL

ziovec

Member
Licensed User
In my webapp project I have different html pages.
I would like to know the current page the user is visiting (it could be the entire URL or even just the /page.html part), how can it be done? ?
 

ziovec

Member
Licensed User
Are the pages static or generated through handlers?
Static pages!

There are bits here and there written by the B4J code, but I guess it's not that relevant.

Oh, each page is connected to a different websocket. Maybe this is a valuable info ?
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
With static pages there is no way to know which page the user is on. If they are connecting to a unique websocket on each page then that is one way to know.

If you are using handlers you can use class name to determine what page they are on, I use this in my application.

B4X:
'Handler class
Sub Class_Globals
    Dim ClassName As String
End Sub

Public Sub Initialize
    Dim jo As JavaObject = Me
    ClassName = jo.RunMethod("getClass",Null)
    ClassName = ClassName.SubString(ClassName.LastIndexOf(".")+1).ToLowerCase
End Sub
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Actually just a thought, you could use a filter to determine which page they are requesting but it depends what you want you are trying to do - plus using static pages arent the best way to do anything dynamic as you lose a lot of control.
 
Upvote 0

ziovec

Member
Licensed User
With static pages there is no way to know which page the user is on. If they are connecting to a unique websocket on each page then that is one way to know.

If you are using handlers you can use class name to determine what page they are on, I use this in my application.

B4X:
'Handler class
Sub Class_Globals
    Dim ClassName As String
End Sub

Public Sub Initialize
    Dim jo As JavaObject = Me
    ClassName = jo.RunMethod("getClass",Null)
    ClassName = ClassName.SubString(ClassName.LastIndexOf(".")+1).ToLowerCase
End Sub

Never used handlers, are there some documentation and/or example I can read about it?
Still learning most of the stuff out there :)

If I'm getting it right I should add to the project a new class module (Server Handler).
In your code, what's exactly ClassName? It should refer to the exact websocket class name?
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Heres the tutorial;


Basically instead of using a static page the server is writing the response. The response can be an HTML page.
 
Upvote 0

ziovec

Member
Licensed User
using static pages arent the best way to do anything dynamic as you lose a lot of control
Thanks for the tips, but I do not need that much dynamics.
Right now I'm just filling datatables trough sql queries, nothing that complicated.

I do usually design static pages with bootstrap studio, it's quick and effective.
In order to generate pages through handlers I'll need to study something else...I guess ABM could be the way? ?
Anyway, it's the next step :D

Heres the tutorial;


Basically instead of using a static page the server is writing the response. The response can be an HTML page.
Thanks! I'll give it a deep look! :D
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
If I'm getting it right I should add to the project a new class module (Server Handler).
In your code, what's exactly ClassName? It should refer to the exact websocket class name?

Each handler is a class. So in the example I could have a class called "hello_world" which returns an HTML page with a "Hello World" message.

Have a read of the turotial, it will make sense.
 
Upvote 0
Top