HTML communication with java?

1

I am working on a small test where I made a table of data in mysql and use hibernate to generate the pojo, the ingnieria inverse and the config file of hibernate cfg in xml. I made a small form in html to try to enter the data and store it in the database, but I am still very new in this and I do not know how to communicate html with java, I would greatly appreciate your help.

<!DOCTYPE html>

<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <form action="PersonalInf.java" method="post">
            <input type="text" name="id" placeholder="Id" >
            <input type="text" name="nombre" placeholder="Nombre" >
            <input type="text" name="apellido" placeholder="Apellido">
            <input type="text" name="sexo" placeholder="Sexo">
            <input type="number" name="edad" placeholder="Edad">
            <button type="submit">Enviar</button>
        </form>
    </body>
</html>

and here I leave the hibernate code:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controlador;

import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import  Modelo.*;

/**
 *
 * @author Aldo
 */        
public class Funcion {

    public void altaUsuarios(PersonalInf user){

        SessionFactory sesion= NewHibernateUtil.getSessionFactory();
        Session session;
        session=sesion.openSession();
        Transaction tx=session.beginTransaction();
        session.save (user);
        tx.commit();
        session.close();
        JOptionPane.showMessageDialog(null, "Insertado correctamente");
    } 
}
    
asked by Aldo Diaz Chaires 29.11.2017 в 01:22
source

1 answer

1

My suggestion is that if you are working with hibernate, use JPA 2 and apply the thymeleaf or jsp templates. SpringBoot Here I leave a couple of examples that served me when I started with hibernate.

example 1

example 2

example 3

    
answered by 29.11.2017 / 02:25
source