Java Reference
In-Depth Information
an application that can accept the submission of an employee form at the address
http:// lo calhost:8080/webapp/employee/save . In this section, we will see
how to use JavaFX to submit data to a web server using the POST method.
How to do it...
To demonstrate how to use HttpRequest to post data to a web server, we will create a simple
form in JavaFX which submits employee information to a backend web server. To do this, we
will use the POST HTTP method of the HttpRequest object to encode and send information
to the server. The next listing provides a shortened version of the code. You can get the full
version from ch06/source-code/src/http/HttpRequestPOST.fx .
1. The first portion of the code builds the GUI for the form. We have seen how to build
GUI forms using standard JavaFX controls in Chapter 4 , Components and Skinning .
Hence, we won't spend too much time on that:
def w = 400;
def h = 200;
var scene:Scene;
var nameRow = HBox {
spacing:7
content:[
VBox{content:[Label{text:"First
Name"},TextBox{id:"fName"}]}
VBox{content:[Label{text:"Last
Name"},TextBox{id:"lName"}]}
]
}
...
var btnRow = HBox {
spacing:7
content:[
Button {
text:"Submit"
action:function(){
formData.visible = true;
postData();
}
}
]
}
 
Search WWH ::




Custom Search