mardi 28 septembre 2021

Getting User input from the web into a java program?

How do I go about setting a java object's property via user input from the web? Like, I want to be able to enter playerOne's and playerTwo's "health" from a website, I know how to do that via command line (with Scanner object) but how do I "scan" from an html page's user input field? Do I have to use JSP or something like that?

static void playGame() {

    Person playerOne = new Seller();
    Person playerTwo = new Buyer();
    playerOne.setHealth(100); // I want this 100 to come from user input on an html page
    playerTwo.setHealth(500); // I want this 500 to come from user input on an html page
    System.out.println("playerOne's health is " + playerOne.getHealth());
    System.out.println("playerTwo's health is " + playerTwo.getHealth());
    
    //.... more code here
}



Aucun commentaire:

Enregistrer un commentaire