Is it possible to create a PopUp in java?

1

I've searched the net, but it only talks about Java Swing. I made a web application with asp and servlet. The issue is that if a query to the DB is empty (no result), I returned a PopUp that says: no result was found, but I can not find how to do it, so my question is whether it is possible to do so. Currently only redirects to the index, but I was asked to put that.

    
asked by elsa 01.06.2016 в 15:41
source

2 answers

1

In a web application it is not complicated, execute alert(mensaje) in the view and you will have a popup with the text that you send in the variable mensaje .

If you need more personalization, you can create a JSP modal or use JQuery Dialog

To achieve this it is important to know WHERE everything is executed (here a summary of the flow of the request skipping the service, business and bbdd layers that any web app has:

  • Send the order from to perform the query (CLIENT - JavaScript)
  • Perform the query on the server side (SERVER - Java)
  • Get an answer (SERVER - Java)
  • Send the result to the view (SERVER - Java)
    • If successful shows the result of the query (CLIENT - JavaScript)
    • If it fails it shows an error message (CLIENT - JavaScript)

As you can see in the final division, in the same way that you send the results of the successful query, you can also send the error message (or null failing) to the view.

An example (very simplified and with ajax call ) would look like this:

$.get("/listaTodosLosObjetos", 
{ "variable": valor } ).done(function( resultado ) {
    // error
    if(resultado == null) {
        alert("No se ha encontrado ningun registro en la base de datos");
    } else {
        // la consulta ha tenido exito
        // muestra la informacion como hasta ahora
    } 
}); 

ADDED: The above is the simple version, you should optimally throw exceptions during the process, launch them in the bean and collect them with .fail , you can also perform default actions with .default in the view:

$.get("/listaTodosLosObjetos", { 
    "variable": valor
})
.done(function( resultado ) {
    // la consulta ha tenido exito
    // muestra la informacion como hasta ahora
})
.fail(function() {
    alert("No se ha encontrado ningun registro en la base de datos");
})
.always(function() {
    // acciones comunes, como por ejemplo, 
    // limpiar algun campo o reiniciar variables.
    valor = "";
}); 
    
answered by 06.06.2016 в 13:28
-1

For that you can use the class " JOptionPane ".

More specifically, if you only want to show a message you can use the following:

JOptionPane.showMessageDialog(null, "Contenido del mensaje", "Título del mensaje", 1);
    
answered by 06.06.2016 в 11:14