• User Newbie

    server da zero

    Salve a tutti ho un problema, vorrei sapere come fare per risolvere questo problema:

    Io ho una stringa e la voglio scrivere su un file che sta sul server, allora la crea con javascript sul client, Come faccio ad inviarla???

    Ho provato con l'oggetto xmlHttpRequest ad inviarla a un file file.class che sta sul server.
    Il file .class l'ho creato con netBeans da questo sorgente ( tutto scritto da me ). Ho messo il file .class sul server, ma non mi funziona !!!!

    sorgente file javascrip sul client

    
    functio start(){
    var testo = "info=noText!";
    
        var xmlHttpRequest;
        function createAjax(){
            if( window.activeXObject ) xmlHttpRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
            else if( window.XMLHttpRequest ) xmlHttpRequest = new XMLHttpRequest;
        }
        function Send( datas ){
            createAjax();
            var destination = "fixer?timeStamp=" + new Date().getTime();
            xmlHttpRequest.open( "POST", destination, true );
            xmlHttpRequest.onreadystatechange = inProgress;
            xmlHttpRequest.setRequestHeader( "Content-type", "application/x-www-form-urlencoded;" );
            xmlHttpRequest.send( datas );
        }
        function inProgress(){
            alert(xmlHttpRequest.responseText);
        }
    
    sand(testo);
    
    }
    
    ```e questo il sorgente java:
    

    import java.io.;
    import javax.servlet.
    ;
    import javax.servlet.http.*;

    public class fixer extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        String rowData = request.getParameter("info");
        store( rowData );
        String resTx = new String(rowData);
        PrintWriter out = response.getWriter();
        try {
            out.println( resTx );
        } finally { 
            out.close();
        }
    } 
    
    public void store( String info ){
        // accesso e memorizzazione
        File db = new File("store.txt");
        FileOutputStream canale;
        try {
            canale = new FileOutputStream(db, true);
            PrintStream writer = new PrintStream(canale);
            writer.println(info);
        } 
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    public String getServletInfo() {
        return "Short description";
    }
    

    }

    Qualcuno potrebbe aiutarmi??

  • Moderatore

    ti sposto nella sezione più appropriata


  • User Newbie

    Ciao scusa potresti dirmi dove hai spostato il mio post??? Grazie


  • Moderatore

    adesso sei nella sezione altri linguaggi per il web