Your ...">

Html to jsp email post post - null parameters

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"

      

/the form

and post to the email.jsp page running in tomcat 5.5, running on another website that I am using which is in flash

this email.jsp appears with null values ​​every time i post data to it - code below

can anyone see what i am 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="test@there.com.au";
 String to="test@where.com";
 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");
%>

      

0


source to share


1 answer


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

The solution is simple, add a "name" attribute to your input elements, for example:



<input type="text" id="name" name="name" />

      

+2


source







All Articles