display in the console

125 views
Skip to first unread message

Darshan

unread,
Jun 19, 2017, 8:12:21 AM6/19/17
to vert.x
hi vertx,
i m trying to learn the vertx, and i succeeded in developing basic app, i.e., welcome to vertx using java language on vertx.

now, i mtrying to develop the same into interactive app.


all i need is now how to get the thing which are written on browser page to display in console?, so that i can understand how the vertx works.
i understood, how vertx display the things into a browser but, by using response.end( ).

Please Find Attached,

with regards,
Darshan
Screenshot from 2017-06-19 17-19-47.png
Screenshot from 2017-06-19 17-20-47.png
Screenshot from 2017-06-19 17-32-18.png
Screenshot from 2017-06-19 17-37-13.png
Screenshot from 2017-06-19 17-40-47.png

Thomas SEGISMONT

unread,
Jun 19, 2017, 9:05:39 AM6/19/17
to ve...@googlegroups.com
Hi,

To write such an application I would use Vert.x Web rather than just Vert.x core.

For reading POST requests content, have a look in particular at http://vertx.io/docs/vertx-web/java/#_request_body_handling

Regards,
Thomas

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/0e6f0104-ca8b-447b-aaf6-1b460937dcaa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ad...@cs.miami.edu

unread,
Jun 19, 2017, 1:28:55 PM6/19/17
to vert.x
Hi,

when you say "display in console", do you mean the web-console of the browser or the terminal-console of the vertx app?

I assume you mean the terminal-console of the vertx app.  If this is the case, just use System.out.println(yourString) to display a message in the vertx terminal.  Note that System.out.println is likely a blocking call, but you probably don't need to worry about that right now.

-Adam

Darshan

unread,
Jun 20, 2017, 3:11:01 AM6/20/17
to vert.x
hi,
i did it i got it displayed in terminal console, but i need to write that in a browser html page by creating <textarea> and should get the display in terminal console.

thanks with regards,
Darshan

ad...@cs.miami.edu

unread,
Jun 20, 2017, 8:20:50 PM6/20/17
to vert.x
Hi,

Ok I think I understand.  There are a lot of steps to doing this.  Start small and build each step incrementally.  The people on this form could write the code for you, but that actually will not help you too much.  Let us know what you have tried and where you are getting stuck.

You need to create a web page that has a textarea in it.  And then put a "send" button underneath it.  When the button is pressed (onclick event), use client side javascript to obtain the contents of the textarea, and then use ajax to send the contents to the vertx server as a GET or POST.  In the vertx server you will need to create a handler (use vertx-web) to handle the ajax requests, grab the content in the request and display it in the terminal.

-Adam

Darshan

unread,
Jun 21, 2017, 3:29:23 AM6/21/17
to vert.x
thank you so much... this guidance means a lot to me. i m trying to do it on my own, if i get stuck i ll inform you sir,... thanks again...

Darshan

unread,
Jun 21, 2017, 9:34:39 AM6/21/17
to vert.x
what if i have a lengthy html file, and i want to display it in browser . where should i put the path name of file, is it in response.end("/some/path/...//..")
or is there any particular way to do it?
thanks in advance.

Thomas SEGISMONT

unread,
Jun 21, 2017, 11:20:36 AM6/21/17
to ve...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.

ad...@cs.miami.edu

unread,
Jun 21, 2017, 9:23:16 PM6/21/17
to vert.x
if you have a static html file (which I think you are referring to), that is  the page with the textarea on it.   If you just want to send that file, use the response.sendFile(path) command, which just sends a single file from a specific file path.

Here is some starter code I grabbed from the docs:  http://vertx.io/docs/vertx-core/java/

vertx.createHttpServer().requestHandler(request -> {
  String file = "";
  if (request.path().equals("/")) {
    file = "index.html";
  } else if (!request.path().contains("..")) {
    file = request.path();
  }
  request.response().sendFile("web/" + file);
}).listen(8080);

-Adam

Darshan

unread,
Jun 22, 2017, 7:41:04 AM6/22/17
to vert.x
hi sir,
as u said, i created index.html file, and also put it in the project file.
i compiled the below code, but its not giving any errors and also the verticle is not deploying in terminal. it shows some failures in terminal. and also it shows the same errors/failures twice. explian the reason. what should i do to execute the code and get it deployed.


PFA,

with regards,
Darshan
Screenshot from 2017-06-22 17-02-39.png
Screenshot from 2017-06-22 17-07-38.png

ad...@cs.miami.edu

unread,
Jun 25, 2017, 12:50:16 AM6/25/17
to vert.x
Darshan,

If I were you I would use Javascript (not Java) when learning vert.x.  In my opinion (and it is just a preference), it is eaiser to get up and running with the Javascipt api, then using Java and having to build things.

So this is what works for me:

var Router = require("vertx-web-js/router");
var server = vertx.createHttpServer();
var router = Router.router(vertx);

router.route("/index/*").handler(function (routingContext) {
    var response = routingContext.response();
    response.putHeader("content-type", "text/html");
    response.sendFile("web/index.html");
});
server.requestHandler(router.accept).listen(8080);


To run this code, copy the above, and save it in a file called server.js, then go into the same directory as the .js file and create a folder called "web", place your index.html in that web folder.  run the following command in the folder that has your .js file:  "vertx run server.js"   And then open up a browser to localhost:8080/index  and your index file will be displayed.  This is just one (of the many ways) to send static content, in this case a specific route was created for a specific file (not to useful, but should give you an idea on how to create routes and such).

Best,

-Adam

DAN

unread,
Jun 26, 2017, 4:48:46 AM6/26/17
to vert.x
hi sir,
i did develop an application... its running smoothly... but i wanted to know where does my data get stored?
like, in a file? or in a datsbase?
if its a file , where can i find it in my project?
my-vertx-first-app/src/main/java/io/vertx/blog/first/MyFirstVerticle.java
i recreated this application, but i m not getting where my entered data is stored.
thanks,
DAN

ad...@cs.miami.edu

unread,
Jun 26, 2017, 4:12:38 PM6/26/17
to vert.x
Dan,

Vertx is a non-opinionated toolkit/framework.  As such, it does not dictate such details as to where and how data is stored.  It is entirely up to you.  You can push your data to a database, store data in a file, or keep the data in memory.   This makes vertx no different from the vast majority of frameworks.  For example, php does not dictate how to save data, nor do old-school java servlets.

With this question, I get the impression that this is your first go at developing server-side web applications.  While vert.x can certainly be your first platform, the vert.x documentation does assume a bit of sophistication and prior knowledge to use vert.x.  Other technology (say php) will have more tutorials on how to save and retrieve your data from a database.  Fundamentally, the concepts are similar with Vert.x, but the underlying tech is different.  I don't want to turn you away from Vert.x, but you might want to concurrently review some intro tutorials on php/servlets/etc.

Best,

-Adam

DAN

unread,
Jun 27, 2017, 12:23:49 AM6/27/17
to vert.x
hi sir,
you are absolutely right... that this is my first first go at developing server-side apps.  thank you so much sir, for all this help... i ll learn PHP and come back as soon as possible, and i ll ask some more doubts. in fact i m new to this coding... so facing little bit difficult. anyway i ll learn as quickly as possible...  once again thank you so much for helping me... if its not too much, can i know which are the sites good for learning PHP?
thanks and regards,
Darshan A N (DAN)

ad...@cs.miami.edu

unread,
Jun 27, 2017, 2:09:19 PM6/27/17
to vert.x
Hi,

The reason I suggested PHP is that there are many introduction tutorials on youtube (and elsewhere) that will give you a sense on how web apps work.  I would just go to youtube and find a tutorial that works for you.  With regard to java, you will probably want to learn how JDBC works.  You can learn about JDBC without using vert.x.   This will provide you with knowlege on how to save your data in a database.  Ultimately, in Vert.x JDBC is optional (one way of doing it), and there is a bit of a mixed history (love hate) between vert.x and JDBC, but that will be a bridge for you to cross much later.

You will want to learn how a web request/response works.  I feel that php is a good accessible pathto learn about that.   But servlets and tomcat is another path that could be taken.

After you learn the basics about web apps, Vert.x will be much more clear.

-Adam

DAN

unread,
Jun 29, 2017, 5:12:37 AM6/29/17
to vert.x
hi sir,
i m happy that you are replying as soon as possible. As you told me i have started to learn PHP in youtube.  As far as my previously asked question, i got to know where does the data entered get stored. The data is not storing in any file, or database. The data entered remains until i restart my app. It uses hashed link to save the temporarily in router.this is my deduction according to what i felt when the data was not storing in any particular file. correct me if i'm wrong.
thanks & regards
DAN

ad...@cs.miami.edu

unread,
Jun 29, 2017, 1:39:21 PM6/29/17
to vert.x
Hi,

Your data will not be stored in any router or hashmap, unless you put your data there.  Your data can be stored wherever you want.  Vertx will not do anything to store your data.  But if you put it in a global in memory hashmap, then that is where it will be.  I would not try to explore where vert,x stores your data by default, because in fact, it does not store your data.  If your data is available in-between requests, it is only because you have placed that data into a data structure that persists in-between requests.

-Adam

DAN

unread,
Jun 30, 2017, 4:12:19 AM6/30/17
to vert.x
hi sir,
thanks again sir, i ll look into it.

-DAN
Reply all
Reply to author
Forward
0 new messages