B4J Question Error in loading a web page

TomDuncan

Active Member
Licensed User
Longtime User
Hi all,
Doing a rebuild on my web server.
Do most of the web pages by a handler.
I can build the page then write it out.
Works ok but, any references like image or css files are not loaded.
I put in a static files folder, so if the html pages are their all loads ok.
So the htm like is not looking in the www folder where the images and Cs files exist.
I am building each page when called for.

Tom
 

TomDuncan

Active Member
Licensed User
Longtime User
Had a look and yes my images folder does not have the leading /
Will fix in the morning and test.
 
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Sorry for the late reply, have been busy with other projects etc.
Still having the problem.
This is what my main area is like..
B4X:
    srvr.Initialize("srvr")
    srvr.Port = 80
    srvr.StaticFilesFolder = File.Combine(File.DirApp, "www")
    srvr.AddHandler("/*", "b4jPages", False)

and the page use..

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    mreq = req
    mresp = resp
    Dim sessionid As String = req.GetSession.Id
'    Log("Request Session ID: " & sessionid)
'    Log("Request URI:" & req.RequestURI)
'    Log("Request FullRequestURI: " & req.FullRequestURI)
'    Log("Request ContentType:  " & req.ContentType)
    Dim s As String = req.RequestURI
    If s.Contains(".html") Then
        Dim htm As String = buildpage.BuildCurrentPage(req.RequestURI)
        If htm <> Null Then resp.Write(htm)
    Else
        resp.Write(s)
    End If  
End Sub

The BuildCurrent page generates the entire web page and returns as a string.
Then that is resp.Write(htm)

With this and the css and image paths have their leading "/" it still does not work.
As I said before if I serve a pre-built page from the www folder all is fine.

the html code produced will not show the background or any other images.
Here is what the view source is..

B4X:
<style>body  {
    background-image: url("/images/fresh_snow.png");
    background-color: #cccccc;
}</style>
Tom
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Have you checked where the page thinks it's being loaded from ?
You can use
B4X:
<script>
    window.alert(window.location.host+"/"+window.location.pathname);
</script>
You may see where the paths are incorrect to get the images and css
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Is it the same as reported from a pre-built page?
 
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Yep, exactly the same 10.1.1.39//index.html,
but the pre-built ones are ok though.
Seems very strange.
 
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Red face time I think.
Just made a little demo up and all worked as it should.
Looks as though I have some <div> functions that have not been closed.
Am checking now.
Sorry about that.
Tom
 
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Have been doing some more testing.
if I have ..
B4X:
    srvr.AddHandler("/test.html", "b4jPages", False)

Then all is fine

but if I put

B4X:
    srvr.AddHandler("/*", "b4jPages", False)

Then it does not work.
How can I then do a call to any web page not a specific one.

Have included a demo. It will run as is, then comment out line 16 and uncomment 17 and try again. (stop/start)

Tom
 

Attachments

  • error.zip
    44.4 KB · Views: 216
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Just tested by adding /ctd/*
Made a folder within www
Still same problem. No image, just like the demo.
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
Modify some lines(not related) . Demo works here. Which browser do you use?
 

Attachments

  • ok.PNG
    ok.PNG
    45.1 KB · Views: 202
  • ok.zip
    45.2 KB · Views: 226
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Yes, thanks have moved the images and css files to the root.
Does this mean that it will have the ctd always in the call.
I.e. ctd.noip.me/ctd/index.html

Tom
 
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Modify some lines(not related) . Demo works here. Which browser do you use?

Yep, thanks the encoding extra bits.
However, if you get rid od the explicit call to test.html it does not work.
However Erel's call re the addition of another folder does.

Using Firefox and Chrome on a Windows 7 computer.
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
I am not sure I understand correctly.

When using
B4X:
srvr.AddHandler("/*", "b4jPages", False)

All the requests to the server (including /images/*.png) will be handled by b4jPages


Using srvr.AddHandler("/ctd/*", "b4jPages", False)
localhost/ctd/index.html works fine here.
 

Attachments

  • ok ctd.zip
    45.2 KB · Views: 221
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Yes, I agree.
Will just have the ctd at the head.
Will have a play in the morning and see if I can get the raspberry up and going again.
New version will use MySQL as well.
 
Upvote 0
Top