Re: sending a JSP page by email
Hi, Thanks for the response. This is really a neat solution of my problem , since I can use Tomcat's JSP engine to create dynamic emails. I copied the solution you posted on your blog. The email is sent OK but, since a use a model 2 web framework like Struts, I send the email, and then I need to send the HTML response back to the client browser, but when I call the forward(request, response) method, I get the typical java.lang.IllegalStateException: Cannot forward after response has been committed exception. I tried overriding the method boolean isCommited() { return false;} in the class EmailResponseWrapper but it doesn't work either. Did you ran into the same problem that I did too? Thanks in advance, Gabriel On Thu, 16 Dec 2004 14:28:22 -0500, Graff, David [EMAIL PROTECTED] wrote: Sorry about the double ... this got lost in the lower message response: http://bijou.dyndns.org/weblog/computer/software/SendingMailFromJavaServlets .html or http://tinyurl.com/5lukz Enjoy. -Original Message- From: Graff, David [mailto:[EMAIL PROTECTED] Sent: Thursday, December 16, 2004 2:22 PM To: 'Tomcat Users List' Subject: RE: sending a JSP page by email Hey kids, I had run into this a while back. I've got a link here to what I did. It's rough and ready so don't expect too much out of it, but it should be enough to get you runnning. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, December 16, 2004 1:52 PM To: tomcat-user@jakarta.apache.org Subject: RE: sending a JSP page by email I *believe*, but don't hold me to it, that you can implement a filter AFTER the JSP renders, in the latest servlet spec. With that, you shouldn't have much trouble taking the output stream and sending it as an eMail. I'd also assume, although I don't know for sure, that you could basically kill the response at that point, so it's not trying to send back to the client or anything. http://bijou.dyndns.org/weblog/computer/software/SendingMailFromJavaServlets .html Enjoy. -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com On Thu, December 16, 2004 1:38 pm, haimra said: I had tried doing the same thing and failed. But after I gained more knowledge I had a new idea that I did not tried yet. I will be happy if you let me know if it works. The basic Idea is that if we used a servelet we had no problem taking the StringBuffer created and coping it into the mail message and not back to the browser. The problem with JSP, it's actually a servlet but we can not control it. In the Java Server Page (O'reilly page 315) book I found some directive element. %@ page buffer=12kb autoFlash=false % When autoFlash=false the JSP container will not flush the buffer until the following script % out.flash() % is used. Maybe there is a way to redirect this output writer to a buffer and email it. What do you think? Haim -Original Message- From: Gabriel Belingueres [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 15, 2004 12:15 AM To: tomcat-user@jakarta.apache.org Subject: sending a JSP page by email Hi, How can I take advantage of Tomcat's JSP processing engine to use a JSP page as a template for an email? That is, I want to do something like a page forwarding from a servlet, but this forwarding process the JSP page and, instead of send it to the browser, it send it by email to somebody. Thanks in advance, Gabriel - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: sending a JSP page by email
I had tried doing the same thing and failed. But after I gained more knowledge I had a new idea that I did not tried yet. I will be happy if you let me know if it works. The basic Idea is that if we used a servelet we had no problem taking the StringBuffer created and coping it into the mail message and not back to the browser. The problem with JSP, it's actually a servlet but we can not control it. In the Java Server Page (O'reilly page 315) book I found some directive element. %@ page buffer=12kb autoFlash=false % When autoFlash=false the JSP container will not flush the buffer until the following script % out.flash() % is used. Maybe there is a way to redirect this output writer to a buffer and email it. What do you think? Haim -Original Message- From: Gabriel Belingueres [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 15, 2004 12:15 AM To: [EMAIL PROTECTED] Subject: sending a JSP page by email Hi, How can I take advantage of Tomcat's JSP processing engine to use a JSP page as a template for an email? That is, I want to do something like a page forwarding from a servlet, but this forwarding process the JSP page and, instead of send it to the browser, it send it by email to somebody. Thanks in advance, Gabriel - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: sending a JSP page by email
I *believe*, but don't hold me to it, that you can implement a filter AFTER the JSP renders, in the latest servlet spec. With that, you shouldn't have much trouble taking the output stream and sending it as an eMail. I'd also assume, although I don't know for sure, that you could basically kill the response at that point, so it's not trying to send back to the client or anything. -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com On Thu, December 16, 2004 1:38 pm, haimra said: I had tried doing the same thing and failed. But after I gained more knowledge I had a new idea that I did not tried yet. I will be happy if you let me know if it works. The basic Idea is that if we used a servelet we had no problem taking the StringBuffer created and coping it into the mail message and not back to the browser. The problem with JSP, it's actually a servlet but we can not control it. In the Java Server Page (O'reilly page 315) book I found some directive element. %@ page buffer=12kb autoFlash=false % When autoFlash=false the JSP container will not flush the buffer until the following script % out.flash() % is used. Maybe there is a way to redirect this output writer to a buffer and email it. What do you think? Haim -Original Message- From: Gabriel Belingueres [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 15, 2004 12:15 AM To: [EMAIL PROTECTED] Subject: sending a JSP page by email Hi, How can I take advantage of Tomcat's JSP processing engine to use a JSP page as a template for an email? That is, I want to do something like a page forwarding from a servlet, but this forwarding process the JSP page and, instead of send it to the browser, it send it by email to somebody. Thanks in advance, Gabriel - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: sending a JSP page by email
Sorry about the double ... this got lost in the lower message response: http://bijou.dyndns.org/weblog/computer/software/SendingMailFromJavaServlets .html or http://tinyurl.com/5lukz Enjoy. -Original Message- From: Graff, David [mailto:[EMAIL PROTECTED] Sent: Thursday, December 16, 2004 2:22 PM To: 'Tomcat Users List' Subject: RE: sending a JSP page by email Hey kids, I had run into this a while back. I've got a link here to what I did. It's rough and ready so don't expect too much out of it, but it should be enough to get you runnning. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, December 16, 2004 1:52 PM To: [EMAIL PROTECTED] Subject: RE: sending a JSP page by email I *believe*, but don't hold me to it, that you can implement a filter AFTER the JSP renders, in the latest servlet spec. With that, you shouldn't have much trouble taking the output stream and sending it as an eMail. I'd also assume, although I don't know for sure, that you could basically kill the response at that point, so it's not trying to send back to the client or anything. http://bijou.dyndns.org/weblog/computer/software/SendingMailFromJavaServlets .html Enjoy. -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com On Thu, December 16, 2004 1:38 pm, haimra said: I had tried doing the same thing and failed. But after I gained more knowledge I had a new idea that I did not tried yet. I will be happy if you let me know if it works. The basic Idea is that if we used a servelet we had no problem taking the StringBuffer created and coping it into the mail message and not back to the browser. The problem with JSP, it's actually a servlet but we can not control it. In the Java Server Page (O'reilly page 315) book I found some directive element. %@ page buffer=12kb autoFlash=false % When autoFlash=false the JSP container will not flush the buffer until the following script % out.flash() % is used. Maybe there is a way to redirect this output writer to a buffer and email it. What do you think? Haim -Original Message- From: Gabriel Belingueres [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 15, 2004 12:15 AM To: [EMAIL PROTECTED] Subject: sending a JSP page by email Hi, How can I take advantage of Tomcat's JSP processing engine to use a JSP page as a template for an email? That is, I want to do something like a page forwarding from a servlet, but this forwarding process the JSP page and, instead of send it to the browser, it send it by email to somebody. Thanks in advance, Gabriel - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: sending a JSP page by email
I *believe*, but don't hold me to it, that you can implement a filter AFTER the JSP renders, in the latest servlet spec. With that, you shouldn't have much trouble taking the output stream and sending it as an eMail. I'd also assume, although I don't know for sure, that you could basically kill the response at that point, so it's not trying to send back to the client or anything. -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com On Thu, December 16, 2004 1:38 pm, haimra said: I had tried doing the same thing and failed. But after I gained more knowledge I had a new idea that I did not tried yet. I will be happy if you let me know if it works. The basic Idea is that if we used a servelet we had no problem taking the StringBuffer created and coping it into the mail message and not back to the browser. The problem with JSP, it's actually a servlet but we can not control it. In the Java Server Page (O'reilly page 315) book I found some directive element. %@ page buffer=12kb autoFlash=false % When autoFlash=false the JSP container will not flush the buffer until the following script % out.flash() % is used. Maybe there is a way to redirect this output writer to a buffer and email it. What do you think? Haim -Original Message- From: Gabriel Belingueres [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 15, 2004 12:15 AM To: [EMAIL PROTECTED] Subject: sending a JSP page by email Hi, How can I take advantage of Tomcat's JSP processing engine to use a JSP page as a template for an email? That is, I want to do something like a page forwarding from a servlet, but this forwarding process the JSP page and, instead of send it to the browser, it send it by email to somebody. Thanks in advance, Gabriel - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: sending a JSP page by email
Hey kids, I had run into this a while back. I've got a link here to what I did. It's rough and ready so don't expect too much out of it, but it should be enough to get you runnning. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, December 16, 2004 1:52 PM To: [EMAIL PROTECTED] Subject: RE: sending a JSP page by email I *believe*, but don't hold me to it, that you can implement a filter AFTER the JSP renders, in the latest servlet spec. With that, you shouldn't have much trouble taking the output stream and sending it as an eMail. I'd also assume, although I don't know for sure, that you could basically kill the response at that point, so it's not trying to send back to the client or anything. http://bijou.dyndns.org/weblog/computer/software/SendingMailFromJavaServlets .html Enjoy. -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com On Thu, December 16, 2004 1:38 pm, haimra said: I had tried doing the same thing and failed. But after I gained more knowledge I had a new idea that I did not tried yet. I will be happy if you let me know if it works. The basic Idea is that if we used a servelet we had no problem taking the StringBuffer created and coping it into the mail message and not back to the browser. The problem with JSP, it's actually a servlet but we can not control it. In the Java Server Page (O'reilly page 315) book I found some directive element. %@ page buffer=12kb autoFlash=false % When autoFlash=false the JSP container will not flush the buffer until the following script % out.flash() % is used. Maybe there is a way to redirect this output writer to a buffer and email it. What do you think? Haim -Original Message- From: Gabriel Belingueres [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 15, 2004 12:15 AM To: [EMAIL PROTECTED] Subject: sending a JSP page by email Hi, How can I take advantage of Tomcat's JSP processing engine to use a JSP page as a template for an email? That is, I want to do something like a page forwarding from a servlet, but this forwarding process the JSP page and, instead of send it to the browser, it send it by email to somebody. Thanks in advance, Gabriel - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: sending a JSP page by email
Here is what I use: // here is a function from my MailUtils class public boolean formSend(String to, String fromAddress, String fromPersonal, String msgSubject, PageContext pc, String templateURL) { if (templateURL == null || templateURL.equals()) { return formSend(to, msgSubject, pc); } String httpHost = pc.getRequest().getServerName(); Enumeration params = pc.getRequest().getParameterNames(); String queryString = ?; if (templateURL.indexOf(?) = 0) queryString = ; while (params.hasMoreElements()) { String param = (String) params.nextElement(); try { queryString += param + = + URLEncoder.encode(StringUtils.encodeHTML(JSPUtils.getParam(pc, param)), UTF-8) + ; } catch (Exception e) { e.printStackTrace(); } } String url = http://; + httpHost + templateURL + queryString; try { // see the Webpage object Webpage wp = new Webpage(url); String msgBody = wp.loadPage(); // replace it your own send mail function send(to, fromAddress, fromPersonal, msgSubject, msgBody, true); } catch (Exception e) { e.printStackTrace(); return false; } return true; } // Here is the Webpage package com.edunet.iwas.util; import java.net.*; import java.io.*; public class Webpage { private static final String NEW_LINE = System.getProperty(line.separator); private String content; private URL u; public Webpage(String urlString) throws MalformedURLException { urlString = StringUtils.replace(urlString, , %20); this.u = new URL(urlString); } public String loadPage() throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader(u.openStream())); String temp; content = ; while ((temp = in.readLine()) != null) content += temp + NEW_LINE; /* you don't really need the NEW_LINE */ in.close(); return content; } public String getContent() { return content; } } Please use it at your own risk... Asim On Tue, 14 Dec 2004 19:15:13 -0300, Gabriel Belingueres [EMAIL PROTECTED] wrote: Hi, How can I take advantage of Tomcat's JSP processing engine to use a JSP page as a template for an email? That is, I want to do something like a page forwarding from a servlet, but this forwarding process the JSP page and, instead of send it to the browser, it send it by email to somebody. Thanks in advance, Gabriel - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]