L
Lindsay
I am trying to send form data via email. I have it set up so that the
code reads a template and replaces variables in the template. I have
tried to add + signs after content, but that does not work either.
Below is the code. It will load the form, but when I submit it, I get
an error message. I will post the error underneath the code. Can
anyone help? I feel I am very close to being done with this page.
<%@page contentType="text/html"%>
<%@ page import="com.fedex.lac.itd.ldap.util.*" %>
<%
String action=request.getParameter("action");
if (action==null) action="";
System.out.println("Action is ="+action);
if (action.equals("Submit")) {
SmtpSender smtpSender=new SmtpSender("smtp.mail.fedex.com");
String from= request.getParameter("email");
String to= request.getParameter("emailaddress");
String subject= "";
subject+= "Purchase Request From";
subject+= " ";
subject+= request.getParameter("shipcountry");
TemplateReader tr=new TemplateReader();
String content= tr.getTemplateFromFile ("plremailrequest.txt");
content=content.replaceAll("%_fname%",request.getParameter("fname"));
content=content.replaceAll("%_lname%",request.getParameter("lname"));
content=content.replaceAll("%_employeenumber%",request.getParameter("empnum"));
content=content.replaceAll("%_telephone%",request.getParameter("tel"));
content=content.replaceAll("%_email%",request.getParameter("email"));
content=content.replaceAll("%_comail%",request.getParameter("comail"));
content=content.replaceAll("%_costcenter%",request.getParameter("costcenter"));
content=content.replaceAll("%_shipaddress1%",request.getParameter("shipadd"));
content=content.replaceAll("%_shipaddress2%",request.getParameter("shipadd2"));
content=content.replaceAll("%_shipcity%",request.getParameter("shipcity"));
content=content.replaceAll("%_shipstate%",request.getParameter("shipstate"));
content=content.replaceAll("%_shipzip%",request.getParameter("shipzip"));
content=content.replaceAll("%_shipcountry%",request.getParameter("shipcountry"));
content=content.replaceAll("%_billaddress1%",request.getParameter("billadd"));
content=content.replaceAll("%_billaddress2%",request.getParameter("billadd2"));
content=content.replaceAll("%_billcity%",request.getParameter("billcity"));
content=content.replaceAll("%_billstate%",request.getParameter("billstate"));
content=content.replaceAll("%_billzip%",request.getParameter("billzip"));
content=content.replaceAll("%_billcountry%",request.getParameter("billcountry"));
content=content.replaceAll("%_qty1%",request.getParameter("qty1"));
content=content.replaceAll("%_descrip1%",request.getParameter("descrip1"));
content=content.replaceAll("%_price1%",request.getParameter("price1"));
content=content.replaceAll("%_qty2%",request.getParameter("qty2"));
content=content.replaceAll("%_descrip2%",request.getParameter("descrip2"));
content=content.replaceAll("%_price2%",request.getParameter("price2"));
content=content.replaceAll("%_qty3%",request.getParameter("qty3"));
content=content.replaceAll("%_descrip3%",request.getParameter("descrip3"));
content=content.replaceAll("%_price3%",request.getParameter("price3"));
content=content.replaceAll("%_qty4%",request.getParameter("qty4"));
content=content.replaceAll("%_descrip4%",request.getParameter("descrip4"));
content=content.replaceAll("%_price4%",request.getParameter("price4"));
content=content.replaceAll("%_qty5%",request.getParameter("qty5"));
content=content.replaceAll("%_descrip5%",request.getParameter("descrip5"));
content=content.replaceAll("%_price5%",request.getParameter("price5"));
content=content.replaceAll("%_qty6%",request.getParameter("qty6"));
content=content.replaceAll("%_descrip6%",request.getParameter("descrip6"));
content=content.replaceAll("%_price6%",request.getParameter("price6"));
content=content.replaceAll("%_nonrev%",request.getParameter("nonrev"));
content=content.replaceAll("%comments%",request.getParameter("comments"));
content=content.replaceAll("%I%",request.getParameter("I"));
content=content.replaceAll("%projectnumber%",request.getParameter("projectnumber"));
content=content.replaceAll("%projectname%",request.getParameter("projectname"));
content=content.replaceAll("%A%",request.getParameter("A"));
content=content.replaceAll("%total_payment%",request.getParameter("total_payment"));
content=content.replaceAll("%B%",request.getParameter("B"));
content=content.replaceAll("%C%",request.getParameter("C"));
content=content.replaceAll("%length%",request.getParameter("length"));
content=content.replaceAll("%desciption_assets%",request.getParameter("description_assets"));
content=content.replaceAll("%D%",request.getParameter("D"));
content=content.replaceAll("%E%",request.getParameter("E"));
content=content.replaceAll("F%",request.getParameter("F"));
content=content.replaceAll("%amt_risks%",request.getParameter("amt_risks"));
content=content.replaceAll("%G%",request.getParameter("G"));
content=content.replaceAll("%H%",request.getParameter("H"));
content=content.replaceAll("%_managername%",request.getParameter("managername"));
content=content.replaceAll("%_managernumber%",request.getParameter("managernumber"));
content=content.replaceAll("%_manageremail%",request.getParameter("manageremail"));
smtpSender.sendEmail(to,subject,content , from);
}
%>
ERROR:
javax.servlet.ServletException
at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:412)
at test2_5._jspService(test2_5.java:149)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:78)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at
org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:534)
at org.apache.tomcat.core.Handler.invoke(Handler.java:280)
at org.apache.tomcat.core.Handler.service(Handler.java:193)
at
org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:445)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:874)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:790)
at
org.apache.coyote.tomcat3.Tomcat3Adapter.service(Tomcat3Adapter.java:64)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
at java.lang.Thread.run(Thread.java:534)
Root cause:
java.lang.NullPointerException
at java.util.regex.Matcher.appendReplacement(Matcher.java:547)
at java.util.regex.Matcher.replaceAll(Matcher.java:661)
at java.lang.String.replaceAll(String.java:1663)
at test2_5._jspService(test2_5.java:116)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:78)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at
org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:534)
at org.apache.tomcat.core.Handler.invoke(Handler.java:280)
at org.apache.tomcat.core.Handler.service(Handler.java:193)
at
org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:445)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:874)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:790)
at
org.apache.coyote.tomcat3.Tomcat3Adapter.service(Tomcat3Adapter.java:64)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
at java.lang.Thread.run(Thread.java:534)
Thanks,
Lindsay
code reads a template and replaces variables in the template. I have
tried to add + signs after content, but that does not work either.
Below is the code. It will load the form, but when I submit it, I get
an error message. I will post the error underneath the code. Can
anyone help? I feel I am very close to being done with this page.
<%@page contentType="text/html"%>
<%@ page import="com.fedex.lac.itd.ldap.util.*" %>
<%
String action=request.getParameter("action");
if (action==null) action="";
System.out.println("Action is ="+action);
if (action.equals("Submit")) {
SmtpSender smtpSender=new SmtpSender("smtp.mail.fedex.com");
String from= request.getParameter("email");
String to= request.getParameter("emailaddress");
String subject= "";
subject+= "Purchase Request From";
subject+= " ";
subject+= request.getParameter("shipcountry");
TemplateReader tr=new TemplateReader();
String content= tr.getTemplateFromFile ("plremailrequest.txt");
content=content.replaceAll("%_fname%",request.getParameter("fname"));
content=content.replaceAll("%_lname%",request.getParameter("lname"));
content=content.replaceAll("%_employeenumber%",request.getParameter("empnum"));
content=content.replaceAll("%_telephone%",request.getParameter("tel"));
content=content.replaceAll("%_email%",request.getParameter("email"));
content=content.replaceAll("%_comail%",request.getParameter("comail"));
content=content.replaceAll("%_costcenter%",request.getParameter("costcenter"));
content=content.replaceAll("%_shipaddress1%",request.getParameter("shipadd"));
content=content.replaceAll("%_shipaddress2%",request.getParameter("shipadd2"));
content=content.replaceAll("%_shipcity%",request.getParameter("shipcity"));
content=content.replaceAll("%_shipstate%",request.getParameter("shipstate"));
content=content.replaceAll("%_shipzip%",request.getParameter("shipzip"));
content=content.replaceAll("%_shipcountry%",request.getParameter("shipcountry"));
content=content.replaceAll("%_billaddress1%",request.getParameter("billadd"));
content=content.replaceAll("%_billaddress2%",request.getParameter("billadd2"));
content=content.replaceAll("%_billcity%",request.getParameter("billcity"));
content=content.replaceAll("%_billstate%",request.getParameter("billstate"));
content=content.replaceAll("%_billzip%",request.getParameter("billzip"));
content=content.replaceAll("%_billcountry%",request.getParameter("billcountry"));
content=content.replaceAll("%_qty1%",request.getParameter("qty1"));
content=content.replaceAll("%_descrip1%",request.getParameter("descrip1"));
content=content.replaceAll("%_price1%",request.getParameter("price1"));
content=content.replaceAll("%_qty2%",request.getParameter("qty2"));
content=content.replaceAll("%_descrip2%",request.getParameter("descrip2"));
content=content.replaceAll("%_price2%",request.getParameter("price2"));
content=content.replaceAll("%_qty3%",request.getParameter("qty3"));
content=content.replaceAll("%_descrip3%",request.getParameter("descrip3"));
content=content.replaceAll("%_price3%",request.getParameter("price3"));
content=content.replaceAll("%_qty4%",request.getParameter("qty4"));
content=content.replaceAll("%_descrip4%",request.getParameter("descrip4"));
content=content.replaceAll("%_price4%",request.getParameter("price4"));
content=content.replaceAll("%_qty5%",request.getParameter("qty5"));
content=content.replaceAll("%_descrip5%",request.getParameter("descrip5"));
content=content.replaceAll("%_price5%",request.getParameter("price5"));
content=content.replaceAll("%_qty6%",request.getParameter("qty6"));
content=content.replaceAll("%_descrip6%",request.getParameter("descrip6"));
content=content.replaceAll("%_price6%",request.getParameter("price6"));
content=content.replaceAll("%_nonrev%",request.getParameter("nonrev"));
content=content.replaceAll("%comments%",request.getParameter("comments"));
content=content.replaceAll("%I%",request.getParameter("I"));
content=content.replaceAll("%projectnumber%",request.getParameter("projectnumber"));
content=content.replaceAll("%projectname%",request.getParameter("projectname"));
content=content.replaceAll("%A%",request.getParameter("A"));
content=content.replaceAll("%total_payment%",request.getParameter("total_payment"));
content=content.replaceAll("%B%",request.getParameter("B"));
content=content.replaceAll("%C%",request.getParameter("C"));
content=content.replaceAll("%length%",request.getParameter("length"));
content=content.replaceAll("%desciption_assets%",request.getParameter("description_assets"));
content=content.replaceAll("%D%",request.getParameter("D"));
content=content.replaceAll("%E%",request.getParameter("E"));
content=content.replaceAll("F%",request.getParameter("F"));
content=content.replaceAll("%amt_risks%",request.getParameter("amt_risks"));
content=content.replaceAll("%G%",request.getParameter("G"));
content=content.replaceAll("%H%",request.getParameter("H"));
content=content.replaceAll("%_managername%",request.getParameter("managername"));
content=content.replaceAll("%_managernumber%",request.getParameter("managernumber"));
content=content.replaceAll("%_manageremail%",request.getParameter("manageremail"));
smtpSender.sendEmail(to,subject,content , from);
}
%>
ERROR:
javax.servlet.ServletException
at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:412)
at test2_5._jspService(test2_5.java:149)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:78)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at
org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:534)
at org.apache.tomcat.core.Handler.invoke(Handler.java:280)
at org.apache.tomcat.core.Handler.service(Handler.java:193)
at
org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:445)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:874)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:790)
at
org.apache.coyote.tomcat3.Tomcat3Adapter.service(Tomcat3Adapter.java:64)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
at java.lang.Thread.run(Thread.java:534)
Root cause:
java.lang.NullPointerException
at java.util.regex.Matcher.appendReplacement(Matcher.java:547)
at java.util.regex.Matcher.replaceAll(Matcher.java:661)
at java.lang.String.replaceAll(String.java:1663)
at test2_5._jspService(test2_5.java:116)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:78)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at
org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:534)
at org.apache.tomcat.core.Handler.invoke(Handler.java:280)
at org.apache.tomcat.core.Handler.service(Handler.java:193)
at
org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:445)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:874)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:790)
at
org.apache.coyote.tomcat3.Tomcat3Adapter.service(Tomcat3Adapter.java:64)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
at java.lang.Thread.run(Thread.java:534)
Thanks,
Lindsay