B4J Tutorial [WebApp] Hello World Web App

lucdrb

Active Member
Licensed User
Longtime User
Hi,

I try to run the program with the bridge (running from /home/pi) on a Raspberry Pi but I couldn't see the web page.

Raspberry Pi side:

^Cpi@raspberrypi~ $ sudo java -jar b4j-bridge.jar
B4J-Bridge v1.00
Waiting for connections (port=6790)...
My IP address is: 192.168.0.12
Connected!

Log when I run the program
2015-06-25 10:19:18.369:INFO::main: Logging initialized @2344ms
2015-06-25 10:19:20.226:INFOejs.Server:main: jetty-9.1.z-SNAPSHOT
2015-06-25 10:19:20.698:WARNejh.MimeTypes:main: java.util.MissingResourceException: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale en_GB
2015-06-25 10:19:21.372:INFOejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@a8195f{/,file:/home/pi/tempjars/www,AVAILABLE}
2015-06-25 10:19:21.420:INFOejs.AbstractNCSARequestLog:main: Opened /home/pi/tempjars/logs/b4j-2015_06_25.request.log
2015-06-25 10:19:21.749:INFOejs.ServerConnector:main: Started ServerConnector@1790bfe{HTTP/1.1}{0.0.0.0:51042}
2015-06-25 10:19:21.769:INFOejs.Server:main: Started @6270ms

Raspberry Pi side
Starting program

Chrome explorer side
HTTP ERROR: 404
Problem accessing /. Reason:

Not Found
Powered by Jetty://

I've try with the jar program in the same directory /home/pi
pi@raspberrypi~ $ sudo java -jar WebAppHelloWorld.jar

2015-06-25 10:04:09.322:INFO::main: Logging initialized @2169ms
2015-06-25 10:04:11.152:INFOejs.Server:main: jetty-9.1.z-SNAPSHOT
2015-06-25 10:04:11.622:WARNejh.MimeTypes:main: java.util.MissingResourceException: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale en_GB
2015-06-25 10:04:12.283:INFOejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@a8195f{/,file:/home/pi/www,AVAILABLE}
2015-06-25 10:04:12.328:INFOejs.AbstractNCSARequestLog:main: Opened /home/pi/logs/b4j-2015_06_25.request.log
2015-06-25 10:04:12.653:INFOejs.ServerConnector:main: Started ServerConnector@b8eb53{HTTP/1.1}{0.0.0.0:51042}
2015-06-25 10:04:12.661:INFOejs.Server:main: Started @6032ms

Same error in the Chrome explore

Help please
Many thanks in advance

Luc
 

lucdrb

Active Member
Licensed User
Longtime User
It's working

Should i've to do that for all the program when I use the jetty server?

Thanks for your help.
 

United Technical Support

Member
Licensed User
Longtime User
Erel,

When I compile this WebAppHelloWorld.zip with B4J 3.50, it show the error as:

2015-08-04 18:47:35.436:INFO::main: Logging initialized @182ms
2015-08-04 18:47:35.545:INFOejs.Server:main: jetty-9.1.z-SNAPSHOT
2015-08-04 18:47:35.561:WARNejh.MimeTypes:main: java.util.MissingResourceException: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale zh_HK
2015-08-04 18:47:35.608:INFOejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@1065c63{/,file:/C:/Documents%20and%20Settings/Owner/My%20Documents/B4j-project/WebAppHelloWorld/Objects/www/,AVAILABLE}
2015-08-04 18:47:35.608:INFOejs.AbstractNCSARequestLog:main: Opened C:\Documents and Settings\Owner\My Documents\B4j-project\WebAppHelloWorld\Objects\logs\b4j-2015_08_04.request.log
2015-08-04 18:47:35.748:INFOejs.ServerConnector:main: Started ServerConnector@1cdf38{HTTP/1.1}{0.0.0.0:51042}
2015-08-04 18:47:35.748:INFOejs.Server:main: Started @513ms

But I simple copied the Object\www\* to C:\Documents and Settings\Owner\My Documents\B4j-project\WebAppHelloWorld\Objects\www\, that is OK now.
Yes, http://10.13.0.9:51042/index.html can have the result now.

But all errors still happen again. Can I setup something to make the error disappear. It is very annoying, thanks!
 
Last edited:

Zoltan Dinya

Member
Licensed User
Longtime User
Hello Erel!
The B4J is great, but I am a real beginner in the web programming, and I hope that You can help me.... When I try to run the web app, I get this: "WebSocket connection to 'ws://212.(my IP).114:51042/ws' failed: Error during WebSocket handshake: Unexpected response code: 404"

The index.html is ok, but the function button doesn't work. 404 error. I send also 2 screenshots.

Browser: Chrome, v45.0.24...
Server: Synology DS415+ with fix IP, port 51042 installed.
In this server, the root www directory is "web" as default and I created a new "www" subfolder, the 3 files are in this. The 51042 port is directed to this, so when I open the (IP):51042/index.html, the program's screen comes up.
But when I cheks the console in the browser, I see the error message.

What can be the problem....? My email is levelezes27@gmail.com

Thank you very much in advance!!

Zoltan from Sweden
 

Attachments

  • Archive.zip
    155.2 KB · Views: 482
  • screen03.zip
    120.4 KB · Views: 470

Zoltan Dinya

Member
Licensed User
Longtime User

I could fix the calculate buttons problem but only on my own computer. First in B4J, you compile and start the little server software, which is invisible, but works. And after that you switches to your web browser, and 127.0.0.1:51042/index.html
I have Chrome (the actual v45) and it works fine on that!

The question is how can I transport this to a real web-server... I donΒ΄t have VPS to run the .jar file, and it is expensive to have a service-provider contract only for this. But I have a Synology DS415+ NAS with fix IP, and I managed to install and setup TOMCAT 7 on it. But it can accept only .war files (is this correct?). With java, I can produce .war packages, I have tested it. Question is, what must I pack into the .war from the project folder? There is: FILES and OBJECTS (subfolders: bin, logs, shell, src, www) and a few files.

Can anyobody write a list about the file, which must be packaged?
 

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

Could you share some snipper code about how to interact bootstrap with B4J ?
 

besoft

Active Member
Licensed User
Longtime User
hi,

The head of the index.html file, I added:

B4X:
  <link href="css/bootstrap.min.css" rel="stylesheet">
 <script src="js/bootstrap.min.js"></script>


Then I used the link to adding the necessary elements.

I'm Bootstrap library copied to the local folder because in my target computer can not access the Internet.

Another example from the index.html file:
B4X:
<style>
.jumbotron {
    background-color: #089B23; /* green */
    color: #ffffff;
    padding: 5px 25px;
    font-family: "Lucida Sans", sans-serif;
}
  .bg-grey {
      background-color: #f6f6f6;
  }
  .container-fluid {
      padding: 10px 10px;
  }
   .container-fluid_buttons {
      padding: 5px 20px;
  }
    .con_tabela {
    padding: 10px 0px;
  }
    .btn-group-vertical {
      padding: 20px 10px;
  }

  th {
    text-align: center;
}

td.color  {
    color: green;
    font-weight: bold;
}
td.color1  {
    color: red;
    font-weight: bold;
}
.navbar-inverse  {
    background-color: #089B23; /* green */
    color: #FFFFFF;
    padding: 10px 25px;
    font-family: "Lucida Sans", sans-serif;
}
</style>
 

Eugenio

Member
Licensed User
Longtime User
Hello!

I'm trying to put the example WebAppHelloWorld to work on my site.

Locally it works perfectly.

Localhost: 51042

I made an upload of the complete www folder to my site, but when access example: http://www.teste.com.br/www/index.html

Displays the standard page of WebAppHelloWorld app but does not perform the calculation.

How do I access? http://www.teste.com.br/www:51042?

So also does not work.

Does anyone could give me some help?

Thank you very much!
 

Jose Cadenas

Member
Licensed User
Longtime User
i can send response to one function

Sub btnCalc_Click (Params AsMap)
Dim ft2 AsFuture = text2.GetVal
Dim ft1 AsFuture = text1.GetVal
If IsNumber(ft1.Value) AND IsNumber(ft2.Value) Then
function response('hola mundo')
Else
function response('X')
End If
End Sub

<script>
//connect to the web socket when the pageis ready.
$( document ).ready(function() {
b4j_connect("/ws");});

function response(resp){
if (resp=='X'){
.....................................
}else{
alert(resp);
.....................................
}
}
</script>
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…