Ciao a tutti, innanzitutto buon anno


Sto implementando per un esame all'uni un mini sito di registrazione ad un corso di master..tra le tante funzioni che deve avere, due di queste sono l'invio automatico di una mail dopo la registrazione con tutti i dati personali, e la possibilità di scriver su un file pdf tutti questi dati...il tutto eseguito con tecologie servlet, jsp, jstl, un minestrone insomma...Di seguito posto il codice che ho fatto io:
Mail.java (classe java)
Mail.jspcodice:import java.util.*; import javax.mail.*; import javax.mail.internet.*; public class Mail { public Mail(String mittente, String destinatario, String testo) { try { Properties props = System.getProperties(); props.put( "mail.smtp.host", "localhost"); props.put( "mail.debug", "true" ); Session session = Session.getDefaultInstance( props ); Message message = new MimeMessage( session ); InternetAddress from = new InternetAddress( mittente ); InternetAddress to[] = InternetAddress.parse(destinatario); message.setFrom( from ); message.setRecipients( Message.RecipientType.TO, to ); message.setSubject("Registrazione confermata a Sito Master"); message.setSentDate( new Date() ); message.setText(testo); Transport.send(message); } catch(MessagingException e) { e.printStackTrace(); } } }
Il problema qui è che funziona tutto ma a intervalli (una volta si e 10 no)..nel senso che la classe singolarmente funziona, il jsp (che contiene anche lettura e scrittura su db) funziona, però appunto a intervalli molto irregolari..ho un dubbio su quell'impostazione "localhost", dato che mi hanno detto di metterla ma non so di preciso a cosa serva (premetto che il tutto deve funzionare da netbeans e sul locale pc, non da server remoti ecc)..codice:<%@page language="java" import="POSTA.*" %> <% String testo = "Ciao brutto gay di un nuovo iscritto.\nusername: "+ request.getParameter("usr")+"\npassword: "+ request.getParameter("pwd")+".\nGAY."; String mittente = "SitoMaster@gmail.com"; String destinatario = request.getParameter("mail"); try { new Mail(mittente, destinatario, testo);// l'ho modificata in modo che prenda questi tre parametri dall'esterno out.println("Mail inviata correttamente a " + destinatario); } catch(Exception e) { out.println("Errore: " + e.toString()); } %>
Pdf.java
idem, la classe partendo da sola me lo scrive il pdf, ma se la relaziono con il codice jsp non mi scrive niente..codice:import java.io.*; import com.lowagie.text.*; import com.lowagie.text.pdf.PdfWriter; public class Pdf { /** Creates a new instance of PdfWriter */ public Pdf() { // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document PdfWriter.getInstance(document, new FileOutputStream("Registrazione.pdf")); // step 3: we open the document document.open(); // step 4: Paragraph p1 = new Paragraph(new Chunk( "This is my first paragraph. ", FontFactory.getFont(FontFactory.HELVETICA, 10))); p1.add("The leading of this paragraph is calculated automagically. "); p1.add("The default leading is 1.5 times the fontsize. "); p1.add(new Chunk("You can add chunks ")); p1.add(new Phrase("or you can add phrases. ")); p1.add(new Phrase("Unless you change the leading with the method setLeading, the leading doesn't change if" + "you add text with another leading. This can lead to some problems.", FontFactory.getFont(FontFactory.HELVETICA, 18))); document.add(p1); Paragraph p2 = new Paragraph(new Phrase( "This is my second paragraph. ", FontFactory.getFont( FontFactory.HELVETICA, 12))); p2.add("As you can see, it started on a new line."); document.add(p2); Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.getFont(FontFactory.HELVETICA, 12)); document.add(p3); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); } }
Pdf.jsp
Mi potete aiutare?codice:<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@page language="java" import="PDF.*" %> <% try { new Pdf(); } catch(Exception e) { out.println("Errore: " + e.toString()); } out.println("Dati registrazione salvati in Registrazione.pdf"); %>
Grazie..ciao ciao :quote:

 
			
			 
					
					
					
						 Rispondi quotando
  Rispondi quotando