• Post Reply Bookmark Topic Watch Topic
  • New Topic

feedback form and jsp and javamail  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to do a feedback form using javamail. I followed a artical "Using JSP with JavaMail" by Jayson Falkner, and it was very helpful. Now I need to add some fields to the form and have them returned and aligned on the returned email, and am having trouble with this.
I am using the following on the sendmail.jsp
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
Properties props = new Properties();
props.put("mail.smtp.host", "mail.pwgsc.gc.ca");
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("mark.fritschen@pwgsc.gc.ca");

InternetAddress to = new InternetAddress("mark.fritschen@pwgsc.gc.ca");
message.addRecipient(Message.RecipientType.TO, to);
String subject = request.getParameter("subject");
String text = request.getParameter("text");
String phone = request.getParameter("phone");
String lName = request.getParameter("lName");

and on the feedback.jsp page
<form action="sendmail.jsp" method="post">
<input type="hidden" name="subject" size="50" value="Forms submission"/>
<input type="hidden" name="Title" value="Comments and Questions"/>
<input type="text" name="lName" value="" size="15">
<input name="phone" value="" size="15">
The subject displays properly
but in the text area, I only get one field to display
I am trying to get the returned email to display like below
Title: Comments and Questions
lName: lname
fName: fname
Department: fjkdjfkd
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's because you are using setText over and over again.

The one field you display would probably be the last field you send to setText() ?

What you want to do is produce a String that contains your entire message, and call setText() once.
I am using a StringBuffer here, because it is the recommended way of concatenating Strings in Java.

And hello to Public Works and Government Services.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!