Reputation: 737
i have now a big doubt, in my j2ee application i do some validations in the class where i do the consult in the ddbb, my problem is that in some case i need to send an alert message to the client, but i think that this is impossible, the problem is that i can not do the validation in the from part or in the servlet because the validation are between diferent consults in diferent databse, then i think i must hard code i little to work with the extrange validations, my problem is...
how i can to send an alert message to the client?
i past some code:
public String [] modificarTablaAdmin (Connection conexion, String [] datosModificar){
String [] resultado=new String[0];
String modificacion = "";
Statement stmt=null;
String [] condicion = null;
String[] condicionB=null;
String dia="";
String mes="";
String condicionGeneral = null;
String horas="";
String minutos="";
String annio = "";
String segundos="";
String ojo ="";
String ojo2 ="";
String base= null;
int traza= 0;
int mesInt = 0;
ArrayList<String> elementos=new ArrayList<String>();
Statement stmt2=null;
Statement stmt3=null;
String cadenaBusqueda = datosModificar (datosModificar);
String [] condicionZ=cadenaBusqueda.split("ESTDEF");
System.out.println("los importantes son"+ condicionZ[0]);
System.out.println("los datos son"+ condicionZ[1]);
String [] condicionW=cadenaBusqueda.split("'");
System.out.println("el 0 dato es"+ condicionW[0]);
System.out.println("el 1 dato es"+ condicionW[1]);
System.out.println("el 2 dato es"+ condicionW[2]);
System.out.println("el 3 dato es"+ condicionW[3]);
System.out.println("el 4 dato es"+ condicionW[4]);
System.out.println("el 5 dato es"+ condicionW[5]);
System.out.println("el 6 dato es"+ condicionW[6]);
System.out.println("el 7 dato es"+ condicionW[7]);
String [] condicionZA=condicionZ[1].split("DESLOT");
System.out.println("los importantes para otra validacion son"+ condicionZA[0]);
System.out.println("los datos validacion de la muerte son"+ condicionZA[1]);
String [] condicionZAW=condicionZA[1].split("'");
System.out.println("el 0 dato es"+ condicionZAW[0]);
System.out.println("el 1 dato es"+ condicionZAW[1]);
System.out.println("el 2 dato es"+ condicionZAW[2]);
System.out.println("el 3 dato es"+ condicionZAW[3]);
System.out.println("el 4 dato es"+ condicionZAW[4]);
try{
stmt2 = conexion.createStatement();
String q2 = "select estad from O02CSFE0.PAI_MAESTRA WHERE APLIC = '" + condicionW[3] + "' AND FORM = '" + condicionW[5] + "' AND VERS = '" + condicionW[7] + "'";
System.out.println(q2);
ResultSet rset2 = stmt2.executeQuery(q2);
while (rset2.next())
{
ojo=rset2.getString("Estad");
System.out.println ("ojoooooooooo " + ojo);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(stmt2!=null){
stmt2.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
try{
stmt3 = conexion.createStatement();
String q3 = "select estad from O02CSFE0.PAI_MAESTRA WHERE APLIC = '" + condicionW[3] + "' AND FORM = '" + condicionW[5] + "' AND VERS = '" + condicionW[7] + "'";
System.out.println(q3);
ResultSet rset3 = stmt3.executeQuery(q3);
while (rset3.next())
{
ojo2=rset3.getString("Tipfor");
System.out.println ("ojoooooooooo nuevo " + ojo2);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(stmt3!=null){
stmt3.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
if ((ojo.equals("P")==true)||(ojo.equals("R")==true))
{
try{
stmt = conexion.createStatement();
//System.out.println("los datos de alta son completos: " + datosModificar(datosModificar));
for (int i=0;i<datosModificar.length;i++)
{
//System.out.println("probando muy importante" + datosModificar[i]);
condicionB=datosModificar[i].split("~");
condicion=datosModificar[i].split("~");
int entrada = 0;
if( condicionB[0].equals("NRBE")==true)
{
condicionGeneral = condicionB[0] + " = '" + condicionB[1] + "'";
entrada = 1;
}
if (condicionB[0].equals("APLIC")==true)
{
entrada = 1;
condicionGeneral += " and " + condicionB[0] + "='" + condicionB[1] + "'";
}
if (condicionB[0].equals("FORM")==true)
{
entrada = 1;
condicionGeneral += " and " + condicionB[0] + "='" + condicionB[1] + "'";
}
if (condicionB[0].equals("VERFOR")==true)
{
entrada = 1;
condicionGeneral += " and " + condicionB[0] + "='" + condicionB[1] + "'";
}
if(condicionB[0].equals("TIPPAP")==true)
{
if((condicion[1].equals("AA")==true)||(condicion[1].equals("AC")==true)||(condicion[1].equals("NE")==true)||(condicion[1].equals("NC")==true))
{
if (ojo2.equals("04")==true)
{
traza = 1;
}
}
if((condicion[1].equals("AB")==true)||(condicion[1].equals("NF")==true))
{
if (ojo2.equals("12")==true)
{
traza = 1;
}
}
if((condicion[1].equals("AG")==true)||(condicion[1].equals("NG")==true))
{
if (ojo2.equals("11")==true)
{
traza = 1;
}
}
}
if (entrada==0)
{
modificacion+= condicion[0] + "='" + condicion[1] + "',";
}
}
Calendar c = Calendar.getInstance();
annio = Integer.toString(c.get(Calendar.YEAR));
if(c.get(Calendar.DATE)<10)
{
dia = "0" + Integer.toString(c.get(Calendar.DATE));
}
else
{
dia = Integer.toString(c.get(Calendar.DATE));
}
mesInt = c.get(Calendar.MONTH);
mesInt = mesInt + 1;
if (mesInt == 13)
{
mesInt = 1;
}
if(mesInt<10)
{
mes = "0" + Integer.toString(mesInt);
}
else
{
mes = Integer.toString(mesInt);
}
if(c.get(Calendar.HOUR_OF_DAY)<10)
{
horas = "0" + Integer.toString(c.get(Calendar.HOUR_OF_DAY));
}
else
{
horas = Integer.toString(c.get(Calendar.HOUR_OF_DAY));
}
if(c.get(Calendar.MINUTE)<10)
{
minutos = "0" + Integer.toString(c.get(Calendar.MINUTE));
}
else
{
minutos = Integer.toString(c.get(Calendar.MINUTE));
}
if(c.get(Calendar.SECOND)<10)
{
segundos = "0" + Integer.toString(c.get(Calendar.SECOND));
}
else
{
segundos = Integer.toString(c.get(Calendar.SECOND));
}
String horaTotal = (horas + minutos +segundos);
String fecha = (annio + mes + dia);
String modificaciones= "FECMOD = '" + fecha + "', HORMOD = '" + horaTotal + "'";
String q = "update O02CSFE0.PAI_ADMINISTRACION set " + modificacion + modificaciones + " where " + condicionGeneral;
/*JOptionPane.showMessageDialog( null, q );*/
System.out.println(q);
if (traza == 1)
{
ResultSet rset = stmt.executeQuery(q);
resultado=new String[elementos.size()];
}
else
{
System.out.println("NI POR PETERRRRRRRRRR");
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(stmt!=null){
stmt.close();
}
}catch(Exception e){
e.printStackTrace();
}
}}
else
{
System.out.println("valor no modificables");
resultado=new String[0];
}
return elementos.toArray(resultado);
}
Upvotes: 0
Views: 935
Reputation: 737
ok i have found the solution..
With this:
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "www.google.es");
Where www.google.es will be a page where i can inform to the user that he do anything bad, in this way you can tell to the cliente that something is wrong, and you only need a web page in your server for that.
Now all is solved, i forced a failure in the consult in the database if the validations are not ok, then my jsp ctach a failure and send an alert message from the server.
With this is not neccesary to do another servle to changed the servlet.
Upvotes: 1
Reputation: 5063
This should make things easy for you.
http://www.easywayserver.com/jsp/JSP-form-validation.htm
Upvotes: 0
Reputation: 3709
If you want to make a call to server only for validation you can use AJAX to make a call to server. In case of validation failures you can return appropriate messages back to client and use javascript to show them on GUI.
For Using AJAX better use some javascript libraries, would recomment JQUERY.
Hoping this helps.
Cheers !!
Upvotes: 1