Author: pete.muir(a)jboss.org
Date: 2008-05-15 11:18:26 -0400 (Thu, 15 May 2008)
New Revision: 8196
Added:
trunk/examples/mail/src/org/jboss/seam/example/mail/MailSenderServlet.java
Modified:
trunk/examples/mail/
trunk/examples/mail/resources/WEB-INF/web.xml
trunk/examples/mail/view/index.xhtml
Log:
Add servlet example to mail example
Property changes on: trunk/examples/mail
___________________________________________________________________
Name: svn:ignore
- test-build
dist
exploded-archives
+ test-build
dist
exploded-archives
test-output
Modified: trunk/examples/mail/resources/WEB-INF/web.xml
===================================================================
--- trunk/examples/mail/resources/WEB-INF/web.xml 2008-05-15 13:25:37 UTC (rev 8195)
+++ trunk/examples/mail/resources/WEB-INF/web.xml 2008-05-15 15:18:26 UTC (rev 8196)
@@ -41,6 +41,17 @@
<url-pattern>*.seam</url-pattern>
</servlet-mapping>
+ <servlet>
+ <servlet-name>Mail Servlet</servlet-name>
+
<servlet-class>org.jboss.seam.example.mail.MailSenderServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Mail Servlet</servlet-name>
+ <url-pattern>/mail/sender</url-pattern>
+ </servlet-mapping>
+
<session-config>
<session-timeout>10</session-timeout>
</session-config>
Added: trunk/examples/mail/src/org/jboss/seam/example/mail/MailSenderServlet.java
===================================================================
--- trunk/examples/mail/src/org/jboss/seam/example/mail/MailSenderServlet.java
(rev 0)
+++ trunk/examples/mail/src/org/jboss/seam/example/mail/MailSenderServlet.java 2008-05-15
15:18:26 UTC (rev 8196)
@@ -0,0 +1,45 @@
+package org.jboss.seam.example.mail;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.servlet.ContextualHttpServletRequest;
+
+public class MailSenderServlet extends HttpServlet
+{
+
+ @Override
+ protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException, IOException
+ {
+ new ContextualHttpServletRequest(req)
+ {
+
+ @Override
+ public void process() throws Exception
+ {
+ Person person = (Person) Component.getInstance(Person.class);
+ String firstname = req.getParameter("name");
+ String email = req.getParameter("email");
+ person.setAddress(email);
+ person.setFirstname(firstname);
+ MailExample mailExample = (MailExample)
Component.getInstance(MailExample.class);
+ mailExample.sendPlain();
+ resp.getWriter().write("Email sent successfully");
+ resp.setStatus(200);
+ }
+
+ }.run();
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ doGet(req, resp);
+ }
+
+}
Property changes on:
trunk/examples/mail/src/org/jboss/seam/example/mail/MailSenderServlet.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/examples/mail/view/index.xhtml
===================================================================
--- trunk/examples/mail/view/index.xhtml 2008-05-15 13:25:37 UTC (rev 8195)
+++ trunk/examples/mail/view/index.xhtml 2008-05-15 15:18:26 UTC (rev 8196)
@@ -38,6 +38,35 @@
<h:messages infoStyle="info" errorStyle="error"
fatalStyle="fatal" warnStyle="warn" />
</h:form>
+ <p>You can also send from inside a servlet:</p>
+
+ <form
action="#{facesContext.externalContext.requestContextPath}/mail/sender"
method="get">
+ <table>
+ <tr>
+ <td>
+ Name
+ </td>
+ <td>
+ <input name="name" />
+ </td>
+ </tr>
+ <tr>
+ <td>
+ Email Address
+ </td>
+ <td>
+ <input name="email" />
+ </td>
+ </tr>
+ <tr>
+ <td></td>
+ <td>
+ <input type="submit" value="Send" />
+ </td>
+ </tr>
+ </table>
+ </form>
+
<h2>Help - it's not working!</h2>
<ul>
<li><b>Setting an SMTP relay</b> - If you have problems sending
emails from this example you might have a firewall
Show replies by date