TomDuncan Active Member Licensed User Longtime User Nov 3, 2015 #1 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
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
B billzhan Active Member Licensed User Longtime User Nov 3, 2015 #2 Absolute vs relative URLs http://stackoverflow.com/questions/2005079/absolute-vs-relative-urls images : www/images/1.png href = "/images/1.png" css : www/css/1.css href = "/css/1.css" If you write href = "1.png" , then the file should be in the same folder of the html page. Last edited: Nov 3, 2015 Upvote 0
Absolute vs relative URLs http://stackoverflow.com/questions/2005079/absolute-vs-relative-urls images : www/images/1.png href = "/images/1.png" css : www/css/1.css href = "/css/1.css" If you write href = "1.png" , then the file should be in the same folder of the html page.
TomDuncan Active Member Licensed User Longtime User Nov 3, 2015 #3 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 Nov 27, 2015 #4 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: Nov 27, 2015 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
Daestrum Expert Licensed User Longtime User Nov 27, 2015 #5 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
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
TomDuncan Active Member Licensed User Longtime User Nov 27, 2015 #6 yep, it says 10.1.1.39//index.html Upvote 0
Daestrum Expert Licensed User Longtime User Nov 27, 2015 #7 Is it the same as reported from a pre-built page? Upvote 0
TomDuncan Active Member Licensed User Longtime User Nov 27, 2015 #8 Yep, exactly the same 10.1.1.39//index.html, but the pre-built ones are ok though. Seems very strange. Upvote 0
Yep, exactly the same 10.1.1.39//index.html, but the pre-built ones are ok though. Seems very strange.
TomDuncan Active Member Licensed User Longtime User Nov 27, 2015 #9 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
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
TomDuncan Active Member Licensed User Longtime User Nov 27, 2015 #10 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 error.zip error.zip 44.4 KB · Views: 395 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
Erel B4X founder Staff member Licensed User Longtime User Nov 27, 2015 #11 The problem is that your handler handles all requests. Add this line at the top of the Handle sub and you will see it: Code: Copy Log(req.RequestURI) I recommend you to use a path such as this: Code: Copy srvr.AddHandler("/dynamic/*", "b4jPages", False) This way static files will be handled correctly. Upvote 0
The problem is that your handler handles all requests. Add this line at the top of the Handle sub and you will see it: Code: Copy Log(req.RequestURI) I recommend you to use a path such as this: Code: Copy srvr.AddHandler("/dynamic/*", "b4jPages", False) This way static files will be handled correctly.
TomDuncan Active Member Licensed User Longtime User Nov 27, 2015 #12 Just tested by adding /ctd/* Made a folder within www Still same problem. No image, just like the demo. Upvote 0
Just tested by adding /ctd/* Made a folder within www Still same problem. No image, just like the demo.
B billzhan Active Member Licensed User Longtime User Nov 27, 2015 #13 Where is /images/fresh_snow.png , /Objects/www/images/fresh_snow.png ? Check if "http://10.1.1.39/images/fresh_snow.png" shows correctly. You can debug tools like Chrome or Firefox firebug (press F12) Upvote 0
Where is /images/fresh_snow.png , /Objects/www/images/fresh_snow.png ? Check if "http://10.1.1.39/images/fresh_snow.png" shows correctly. You can debug tools like Chrome or Firefox firebug (press F12)
B billzhan Active Member Licensed User Longtime User Nov 27, 2015 #14 Modify some lines(not related) . Demo works here. Which browser do you use? Attachments ok.PNG 45.1 KB · Views: 522 ok.zip ok.zip 45.2 KB · Views: 397 Upvote 0
TomDuncan Active Member Licensed User Longtime User Nov 27, 2015 #15 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
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
TomDuncan Active Member Licensed User Longtime User Nov 27, 2015 #16 billzhan said: Modify some lines(not related) . Demo works here. Which browser do you use? Click to expand... 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 said: Modify some lines(not related) . Demo works here. Which browser do you use? Click to expand... 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.
B billzhan Active Member Licensed User Longtime User Nov 27, 2015 #17 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 ok ctd.zip ok ctd.zip 45.2 KB · Views: 396 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.
TomDuncan Active Member Licensed User Longtime User Nov 27, 2015 #18 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
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.