views:

1811

answers:

2

I have a simple form

form action="email.jsp" method="post"

        <label for="firstname">Your Name: </label>
              input type="text" id="name"<br/>
        <label for="email">Your Email: </label>
              input type="text" id="address"<br/>
    <label for="message">Message: </label>
              textarea size="30" rows="4" class="expand" id="comments"</textarea<br/>
        input type="submit" value="Send" input type="reset"

/form

and am posting to a email.jsp page running in tomcat 5.5, working for another website i use that is in flash

this email.jsp is coming up with null values every time i post data to it - code below

can anyone see what i'm doing wrong?

<%@ page import="sun.net.smtp.SmtpClient, java.io.*, javax.servlet.http.HttpServletResponse, javax.servlet.jsp.PageContext" %>
<%
 String name = request.getParameter("name"); 
 out.print(name);
 String address = request.getParameter("address");
 String comments = request.getParameter("comments");
 String from="[email protected]";
 String to="[email protected]";
 try{
     SmtpClient client = new SmtpClient("localhost");
     client.from(from);
     client.to(to);
     PrintStream message = client.startMessage();
     message.println("From: " + from);
     message.println("To: " + to);
     message.println();
     message.println("Enquiry :-) from " + name + " at " + address);
     message.println();     
     message.println("Details: "+ comments);
     client.closeServer();
  }
  catch (IOException e){    
     System.out.println("ERROR SENDING EMAIL:"+e);
  }
out.print("Email Sent Correctly");
%>
+2  A: 

Your HTML is a bit garbled, but it looks like you're not specifying the "name" attribute for your inputs. The "id" attribute is good for referencing your field from a <label> or for accessing your inputs from Javascript, but the browser will not use it in the POST request.

The solution is simple, add the "name" attribute to your input elements, like this:

<input type="text" id="name" name="name" />
Alexander Malfait
A: 

correct, silly oversight

...slaps back of hand... I shouldn't copy and paste code without reading it