Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 18
  1. #1

    [JAVA/JSP] errore

    ragazzi sapete dirmi cos'č questo errore e come si risolve:

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    java.lang.NullPointerException
    GestioneXML.aggiungiClientiXML(GestioneXML.java:33 )
    ServletRegistrati.doPost(ServletRegistrati.java:48 )
    ServletRegistrati.doGet(ServletRegistrati.java:21)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)

    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.

  2. #2
    Nessuno mi sa aiutare? vi servono altre informazioni?

    Grazie. Ciao

  3. #3
    generalmente stai usando un variabile che vale null. dovresti postare il codice relativo all'errore....

  4. #4
    Grazie per la risposta.

    Questa č la servlet:
    codice:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.lang.String;
    
    
    public class ServletRegistrati extends HttpServlet{
    	
    	public void goToPage(String url,HttpServletRequest request,HttpServletResponse response)
    								 throws  ServletException, IOException{
    						 	
    					RequestDispatcher dispatcher= getServletContext().getRequestDispatcher(url);
    					dispatcher.forward(request,response);       			 
    						 						 
    								 }	
    
    	public void doGet(HttpServletRequest request,HttpServletResponse response )
    					 throws  ServletException, IOException{
    	             
    	                  doPost(request,response);
    					 }
    	     	
    	public void doPost(HttpServletRequest req, HttpServletResponse res) 
    	             throws ServletException, IOException{ 
    
    	 	 HttpSession session= req.getSession(true);
    	 	
    	 	 // otteniamo la path del server
    		 ServletContext p = getServletContext();
    		 String pathserver=p.getRealPath("/"); 
    		 String pathdef=pathserver+"database/clienti.xml";
    
    		String[] valoreParam = new String[2];
    
    		valoreParam[0] = req.getParameter("login");
    		valoreParam[1] = req.getParameter("password");
    
    	// memorizzo anche tali parametri in una stringa per il riepilogo		
    	String iscrizioneCliente="<tr> <td> Login: "+valoreParam[0]+"</td>"+
    		 "<tr> <td> Password: "+valoreParam[1]+"</td>";		
    
    		 // crea un oggetto GestioneXML
          	 GestioneXML gestione = new GestioneXML(); 
    
    
    		 // invoco il metodo aggiungiClientiXML
    		 String xml=gestione.aggiungiClientiXML(pathdef,valoreParam);
    
             // setto un attributo per l'oggetto session
    		 session.setAttribute("iscrcliente",iscrizioneCliente);
    	             
             // salvataggio database clienti su file clienti.xml          	 
    		 File file = new File(pathdef); 
    		 if (file!=null) 
    		  { 
    		  try{		  
    		  	FileOutputStream fs = new FileOutputStream(file);
    		  	PrintStream ps = new PrintStream(fs);	 	
    		  	ps.println(xml);
    		  	fs.close();	
    		  	} catch(Exception e){	e.printStackTrace();}
    		  }
    	    		 
    	     goToPage("/riepilogo_cliente.jsp",req,res);
    	     
    		}
    	  
    	 
    }
    e questo č la classe GestioneXML:

    codice:
    import org.jdom.*;
    import org.jdom.input.*;
    import org.jdom.output.*;
    import java.util.*;
    import java.io.*;
    
    public class GestioneXML {    
      	         	
    	   public GestioneXML(){}
           
     	
    		// metodo x aggiungere clienti al file clienti.xml 
    		public String aggiungiClientiXML(String pathin,String[] valori){
    	    
    		  Document doc=null;
    		  Element root=null;
    		  String outxml=null;
    	    
    		  SAXBuilder sbuilder = new SAXBuilder(true);	
    		   
    		  try{
    			  doc = sbuilder.build(pathin);
                              System.out.println(pathin+" č valido");   
    			 }
    		  catch(JDOMException e){
    				  System.out.println(pathin+"non č valido");
    				  System.out.println(e.getMessage());	
    			   }
    		  catch(IOException e){
    				  System.out.println("Non Posso controllare "+pathin);
    				  System.out.println(e.getMessage());	
    			   }
    		root =doc.getRootElement();
    
    		/* ISTANZIAMO ALTRI OGGETTI Element PASSANDOGLI LE STRINGHE
    			 CHE SARANNO I NOMI DEI NOSTRI TAG  */
    		  Element cliente = new Element("cliente");
    		  Element elogin = new Element("login");
    		  Element epassword = new Element("password");
    
    // ASSEGNAMO DEI VALORI AI TAG 
    		  elogin.addContent(valori[0]);
    		  epassword.addContent(valori[1]);
    
    // AGGIUNGIAMO I TAG AL TAG cliente	  
    		  cliente.addContent(elogin);
    		  cliente.addContent(epassword);
    
     // AGGIUNGIAMO IL TAG cliente AL SUPERTAG root 
    		  root.addContent(cliente);
    
    //ISTANZIAMO LA CLASSE XMLOutputter CHE CI PERMETTE DI FORMATTARE IL FILE XML. */
    		  XMLOutputter xout = new XMLOutputter("  ",true);
    			
    		  // SCRIVIAMO IL DOCUMENTO IN UNA STRINGA
    		  outxml =xout.outputString(doc);		
    		  return outxml; 
    		  				
    		}// fine metodo aggiungiClientiXML 	
    }
    Grazie. CIAO

  5. #5
    Help me.



    Nessuno mi aiuta?

    Ciao ciao

  6. #6
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    la riga con l'errore č la 33 nel metodo aggiungiClientiXML della classe GestioneXML GestioneXML.aggiungiClientiXML(GestioneXML.java:33 )

  7. #7
    L'errore č qui:

    codice:
    root =doc.getRootElement();
    Ma io non vedo niente di sbagliato. Sarā che non sono pratico.
    Dove ho sbagliato?

  8. #8
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    ho visto che hai messo un try catch con dei system.out
    nella console scrive qualcosa prima dell'eccezione?

  9. #9
    NO. Niente

  10. #10
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    impossibile
    hai messo nel try un print con pathin+" č valido" e nei catch altri print
    qualcosa deve scrivere, oppure l'eccezione viene generata in doc = sbuilder.build(pathin);

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.