B4J Question B4J not running in server

Tadeu Botelho

Member
Licensed User
Longtime User
Hello
My B4J server was up and now stopped. I tested firewall and anti-virus but could not identify the source of the problem.
I'm working on server development by following the following example: https://www.b4x.com/android/forum/t...device-desktop-and-web-reports.37254/#content
I noticed that .JAR itself has the implicit java server. So I was very confused because the message in the browser appears the answer: Not found.
Does anybody know how to solve this?
Thank you
 

Attachments

  • Problem.PNG
    129.5 KB · Views: 307

Ormente

Member
Licensed User
Longtime User
The jetty server is running, but it can't find the resource requested by the browser (root document / usually index.html), so it's likely a routing or path configuration problem.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
so it's likely a routing or path configuration problem
Jetty serves (out of box) anything in the www folder/sub-folders and the handlers you have setup up. In your program, the only two handlers you have set up are AddAnimal and Report, therefore http://localhost:51042/AddAnimal and http://localhost:51042/Report are valid "pages". If you want Jetty to serve something up when you access just http://localhost:51042, then do

1) Create a www folder in the same location of your .jar file and then put an index.html file in that folder (could also be an index.jsp).

OR

2) Create a new Server Handler class module and use
B4X:
srvr.AddHander("","NameOfYourNewServerHandlerClass",False)
before srvr.Start
 
Last edited:
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
I am new to B4J.
I have created the www folder and created an index.html file in that folder in the same location as the .jar file.
I have created a new class module handler "MyNewServerHandlerClass"

I have added:
B4X:
srvr.AddHander("","MyNewServerHandlerClass",False)

The index.html file does not load.
If I write some code in "MyNewServerHandlerClass" such as:
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    resp.Write("Hello")
End Sub

"Hello" shows up in http://localhost:51042
But NOT the contents of the index.html file.

How do I go about displaying the index.html file itself?
Thanks

edit: If I type http://localhost:51042/index.html I can view the file.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
My answer should have contained an or. Do either #1 or #2. If you want index.html to work, then remove the handler. I’m updating my previous answer.
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
I tried everything else except...
removing the handler.

Thanks for this. It advances my understanding of the B4J processes.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…