2017-09-14 1 views
0

Javafx Scene Builder 2.0을 사용하여 양식을 만들었습니다. 양식이 작동하고 양식 요소 값으로 설정된 변수가 있습니다. 또한 포스트 데이터를 받아서 데이터를 데이터베이스에 삽입하는 PHP 스크립트를 만들었습니다.Javafx 만든 양식에서 HTTP POST 요청 보내기

javafx 폼 데이터를 HTTP POST를 통해 PHP 스크립트로 보내면 도움이 필요합니다.

여기 내 자바 코드입니다.

Main.java

package sample; 

import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.stage.Stage; 

public class Main extends Application { 

    @Override 
    public void start(Stage primaryStage) throws Exception{ 
     Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); 
     primaryStage.setTitle("Orbis Cob Submit"); 
     primaryStage.setScene(new Scene(root, 800, 600)); 
     primaryStage.show(); 

    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

Controller.java

package sample; 

import javafx.collections.FXCollections; 
import javafx.collections.ObservableList; 
import javafx.fxml.FXML; 
import javafx.scene.control.*; 
import javafx.scene.text.Text; 
import java.io.IOException; 

import java.io.IOException; 
import java.util.Observable; 

public class Controller { 
    //Send Vars 
    private String sendDataType; 
    private String sendCobTarget; 
    private String sendVendor; 
    private String sendCobName; 
    private String sendDealerID; 
    private String sendJobType; 
    private String sendStartDate; 
    private String sendEndDate; 
    private String sendAmount; 
    private String sendCost; 
    private String sendDataDescription; 
    private DataBase db = new DataBase(); 

    //Data list for drop downs 
    ObservableList<String> dataTypeList = FXCollections.observableArrayList("BK", "BR", "DB", "DEQ", "FI", "MB", "OB", "SAT", "SURN"); 
    ObservableList<String> cobTargetList = FXCollections.observableArrayList("Sales", "Services", "Both"); 
    ObservableList<String> vendorList = FXCollections.observableArrayList("SJO", "OCZ","Inhouse"); 
    ObservableList<String> jobTypeList = FXCollections.observableArrayList("Mail", "Digital"); 

    //Form Elements 
    @FXML 
    public ChoiceBox dataType; 

    @FXML 
    public ChoiceBox cobTarget; 

    @FXML 
    public ChoiceBox vendor; 

    @FXML 
    public Button button; 

    @FXML 
    public Text message; 

    @FXML 
    public TextField cobName; 

    @FXML 
    public TextField dealerID; 

    @FXML 
    public ChoiceBox jobType; 

    @FXML 
    public DatePicker startDate; 

    @FXML 
    public DatePicker endDate; 

    @FXML 
    public TextField sentAmount; 

    @FXML 
    public TextField cost; 

    @FXML 
    public TextField dataDescription; 


    @FXML 
    private void initialize(){ 
     dataType.setItems(dataTypeList); 
     cobTarget.setItems(cobTargetList); 
     vendor.setItems(vendorList); 
     jobType.setItems(jobTypeList); 

     button.setOnAction(e -> { 
      this.sendDataType = dataType.getValue().toString(); 
      this.sendCobTarget = cobTarget.getValue().toString(); 
      this.sendVendor = vendor.getValue().toString(); 
      this.sendCobName = cobName.getText(); 
      this.sendDealerID = dealerID.getText(); 
      this.sendJobType = jobType.getValue().toString(); 
      this.sendStartDate = startDate.getValue().toString(); 
      this.sendEndDate = endDate.getValue().toString(); 
      this.sendAmount = sentAmount.getText(); 
      this.sendCost = cost.getText(); 
      this.sendDataDescription = dataDescription.getText(); 

      //Send Field Data to HTTP POST REQUEST 

     }); 
    } 



} 

답변

0

가장 좋은 방법은 HTTP (S) 쉽게 요청을 전송 만든다있는 같은 라이브러리를 사용하는 것입니다.

는이처럼 사용

Unirest.post("http://httpbin.org/post") 
    .field("sendDataType", dataType.getValue().toString()) 
    .field("sendCobTarget", cobTarget.getValue().toString()) 
    .field("sendDataType", dataType.getValue().toString()) 
    .field("sendCobTarget", cobTarget.getValue().toString()) 
    .field("sendVendor", vendor.getValue().toString()) 
    .field("sendCobName", cobName.getText()) 
    .field("sendDealerID", dealerID.getText()) 
    .field("sendJobType", jobType.getValue().toString()) 
    .field("sendStartDate", startDate.getValue().toString()) 
    .field("sendEndDate", endDate.getValue().toString()) 
    .field("sendAmount", sentAmount.getText()) 
    .field("sendCost", cost.getText()) 
    .field("sendDataDescription", dataDescription.getText()) 
    .asJson(); 

당신이 보낼 값에 각 필드를 설정해야 할 것입니다.

+0

질문에서 모든 필드를 보내지 않는 단축과 별도로 내가 잘못 했습니까? – jrtapsell

+0

내 입력란에 문제가있는 경우 모든 입력란을 포함하도록 확장되었습니다. – jrtapsell