B4J Tutorial [WebApp] Hello World Web App

Discussion in 'B4J Tutorials' started by Erel, Apr 10, 2014.

  1. lucdrb

    lucdrb Member Licensed User


    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:

    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:INFO:eek:ejs.Server:main: jetty-9.1.z-SNAPSHOT
    2015-06-25 10:19:20.698:WARN:eek:ejh.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:INFO:eek:ejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@a8195f{/,file:/home/pi/tempjars/www,AVAILABLE}
    2015-06-25 10:19:21.420:INFO:eek:ejs.AbstractNCSARequestLog:main: Opened /home/pi/tempjars/logs/b4j-2015_06_25.request.log
    2015-06-25 10:19:21.749:INFO:eek:ejs.ServerConnector:main: Started ServerConnector@1790bfe{HTTP/1.1}{}
    2015-06-25 10:19:21.769:INFO:eek:ejs.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:INFO:eek:ejs.Server:main: jetty-9.1.z-SNAPSHOT
    2015-06-25 10:04:11.622:WARN:eek:ejh.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:INFO:eek:ejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@a8195f{/,file:/home/pi/www,AVAILABLE}
    2015-06-25 10:04:12.328:INFO:eek:ejs.AbstractNCSARequestLog:main: Opened /home/pi/logs/b4j-2015_06_25.request.log
    2015-06-25 10:04:12.653:INFO:eek:ejs.ServerConnector:main: Started ServerConnector@b8eb53{HTTP/1.1}{}
    2015-06-25 10:04:12.661:INFO:eek:ejs.Server:main: Started @6032ms

    Same error in the Chrome explore

    Help please
    Many thanks in advance

  2. Erel

    Erel Administrator Staff Member Licensed User

    The server logs are fine.

    Can you post the link that you are trying to access?
  3. lucdrb

    lucdrb Member Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

    You will need to manually copy the www folder to the device. It should be copied to the tempjars folder.
  5. lucdrb

    lucdrb Member Licensed User

    :DIt's working :D

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

    Thanks for your help.
  6. Erel

    Erel Administrator Staff Member Licensed User

    B4J-Bridge doesn't copy files except of the files in the Files folder. If your program relies on any other files then you need to manually copy them.
  7. lucdrb

    lucdrb Member Licensed User

    Ok it's clear

    Thank you
  8. United Technical Support

    United Technical Support Member Licensed User


    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:INFO:eek:ejs.Server:main: jetty-9.1.z-SNAPSHOT
    2015-08-04 18:47:35.561:WARN:eek:ejh.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:INFO:eek:ejsh.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:INFO:eek:ejs.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:INFO:eek:ejs.ServerConnector:main: Started ServerConnector@1cdf38{HTTP/1.1}{}
    2015-08-04 18:47:35.748:INFO:eek:ejs.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, 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: Aug 4, 2015
  9. Erel

    Erel Administrator Staff Member Licensed User

    This is not an error. It is just information messages that are printed from the jServer library.
  10. Zoltan Dinya

    Zoltan Dinya Member Licensed 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

    Attached Files:

  11. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question (and don't limit it to a single member ;) ).
  12. ViMeAv ICT

    ViMeAv ICT Member Licensed User

    When I use : the calculate button doesn't work.
    When I use : the calculate button does work.
    And how can I stop the service?
    How do I start the service at a hostingprovider after uploading the files by ftp?
  13. Zoltan Dinya

    Zoltan Dinya Member Licensed 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
    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?
  14. Erel

    Erel Administrator Staff Member Licensed User

    Please start new threads for these questions.
  15. besoft

    besoft Active Member Licensed User

    I was just updated the web site using Bootstrap.;)

    hibrid0 and jinyistudio like this.
  16. jinyistudio

    jinyistudio Active Member Licensed User


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

    besoft Active Member Licensed User


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

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

    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:
    .jumbotron {
    #089B23; /* green */
        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;
    Ed Brown and tuhatinhvn like this.
  18. Eugenio

    Eugenio Member Licensed User


    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!
  19. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
  20. Jose Cadenas

    Jose Cadenas Member Licensed 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')
    function response('X')
    End If
    End Sub

    //connect to the web socket when the pageis ready.
    $( document ).ready(function() {

    function response(resp){
    if (resp=='X'){
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice