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
 
Had a look and yes my images folder does not have the leading /
Will fix in the morning and test.
 
Upvote 0
Sorry for the late reply, have been busy with other projects etc.
Still having the problem.
This is what my main area is like..
Code: Copy
    srvr.Initialize("srvr")
    srvr.Port = 80
    srvr.StaticFilesFolder = File.Combine(File.DirApp, "www")
    srvr.AddHandler("/*", "b4jPages", False)

and the page use..

Code: Copy
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..

Code: Copy
<style>body  {
    background-image: url("/images/fresh_snow.png");
    background-color: #cccccc;
}</style>
Tom
 
Last edited:
Upvote 0
Have you checked where the page thinks it's being loaded from ?
You can use
Code: Copy
<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
Is it the same as reported from a pre-built page?
 
Upvote 0
Yep, exactly the same 10.1.1.39//index.html,
but the pre-built ones are ok though.
Seems very strange.
 
Upvote 0
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
Have been doing some more testing.
if I have ..
Code: Copy
    srvr.AddHandler("/test.html", "b4jPages", False)

Then all is fine

but if I put

Code: Copy
    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

Upvote 0
Just tested by adding /ctd/*
Made a folder within www
Still same problem. No image, just like the demo.
 
Upvote 0
Modify some lines(not related) . Demo works here. Which browser do you use?
 

Attachments

  • ok.PNG
    ok.PNG
    45.1 KB · Views: 522
  • ok.zip
    ok.zip
    45.2 KB · Views: 397
Upvote 0
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
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
I am not sure I understand correctly.

When using
Code: Copy
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

Upvote 0
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
Back
Top