Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/10/2005, 11:27
Ace_ventura
 
Fecha de Ingreso: octubre-2005
Mensajes: 188
Antigüedad: 19 años, 4 meses
Puntos: 0
Ayuda con un formulario

Hola a todos soy nuevo en esto de Jsp y necesito un pekeño favor. La idea es por medio de un formulario registrar unos usuarios. Estos deben ingresar un login, password y nombre completo y luego debo grabar o escribir estos datos en un archivo de texto plano. He intentado muchas formas pero no doy con el chiste
Código PHP:
<html>
<
head><title>Registro de usuarios nuevos</title></head>
<
body>
<
h1><b><center>REGISTRO</center></b></h1>
<
form action="registro.jsp" method="GET" >
<
table align="center" cellpadding="2" cellspacing="2" border="1" width="45%" bgcolor="#dddddd">
            <
tr>
                <
th>Login <input type="text" name="login" size="15"></th>
            </
tr>    
            <
tr>    
                <
th>Password <input type="password" name="password" size="15"></th>
            </
tr>
            <
tr>
                <
th>Nombre y Apellido <input type="text" name="nomape" size="20"></th>
            </
tr
            <
tr>
                <
th><input type="submit" value="Aceptar" />
                <
input type="reset" value="Borrar" /></th>
            </
tr>
</
table>
</
form>
<
hr
esto es el formulario de inicio aki llamo a una pagina jsp llamada registro ke va y crea el archivo de texto plano.Aki es donde tengo mis dudas
Código PHP:
<html>
<
head><title>Registro de usuarios nuevos</title></head>
<
body>

<
jsp:useBean id="u" class="ejemplo.Insertar" scope="request"/>

<
jsp:setProperty name="u" property="login"/>
<
jsp:setProperty name="u" property="password"/>
<
jsp:setProperty name="u" property="nomape"/>

</
body>
</
html
y llamo una funcion
Código PHP:
import java.security.MessageDigest
import java.io.*; 

public class 
Insertar
    public static 
String Archivo
    protected 
String loginpasswordnomape;
    
    
Insertar(String arch){ 
        
this.Archivo arch
    } 
    
    public 
void setLogin(String login){
        
this.login login;
    }
    
    public 
void setPassword(String password){
        
this.password password;
    }
    
    public 
void setNomape(String nomape){
        
this.nomape nomape;
    }
    
    public 
String getLogin(){
        return 
this.login;
    }
    
    public 
String getPassword(){
        return 
this.password;
    }
    
    public 
String getNomape(){
        return 
this.nomape;
    }
     
    public static 
void Escribir(String datos){ 
        try 
        { 
            
FileWriter fw = new FileWriter(Archivo,true); 
            
BufferedWriter bw = new BufferedWriter(fw); 
            
PrintWriter escritor = new PrintWriter(bw); 
            
escritor.print(datos);
            
escritor.println();
            
escritor.close (); 
        } 
        catch(
Exception e
        { 
            
System.out.println("\n\nError: " e); 
        } 
    } 
     
    private static 
String hash(String clearthrows Exception 
        
MessageDigest md MessageDigest.getInstance("MD5"); 
        
byte[] md.digest(clear.getBytes()); 

        
int size b.length
        
StringBuffer h = new StringBuffer(size); 
        for (
int i 0sizei++) { 
            
int u b[i]&255// unsigned conversion 
            
if (u<16) { 
                
h.append("0"+Integer.toHexString(u)); 
            } else { 
                
h.append(Integer.toHexString(u)); 
            } 
        } 
        return 
h.toString(); 
    } 

    
/** 
     * Encripta un String con el algoritmo MD5. 
     * @return String 
     * @throws Exception 
     */ 
    
public static String encriptar(String palabra)throws Exception 
        
String pe=""
        try { 
            
pe hash(palabra); 
        } catch (
Exception e) { 
            throw new 
Error("<strong>Error: Al encriptar el password</strong>");     
        } 
        return 
pe
    }
    
// para probar
    
public void registrar() throws Exception 
        
Insertar arch = new Insertar("myarchivo.txt"); 
        
String myText this.login;
        
String myText1 this.password;
        
String myText2 this.nomape;
        
String texto encriptar(myText1);
        
arch.Escribir(myText "," texto "," myText2);
    }

Aki utilice unas funciones ke encontre en esta misma pagina muy utiles.
Cualkier ayuda se agradece
Una pregunta: siempre ke se invoke una funcion desde una pagina jsp esta debe tener un valor de retorno?
En el jsp yo podria solo decir: u.registrar() o esta funcion debe retornar algo.
Gracias