JSP Contact Form - Submit to Gmail

I am new to JSP and I am working on a project to create a contact form page. I use Tomcat as my local host. I created a form and saved it in JSP. This is a very simple form. With a name, email, subject, message.

Now I need to give him action using JSP and send it to Gmail. Therefore, when someone uses the contact form, he will be sent to the gmail address. I created a new JSP file and named it mail.jsp.

But now I'm completely lost. Can someone help me please?

Here is the first page, contact form:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Contact Form</title> </head> <body> <form method="post" action="mail.jsp"> <center><h4>Contact us:</h4></center> <br /> <center>Name: <input type="text" name="name"><br /></center> <br> <center>Email: <input type="text" name="email"><br /></center> <br> <center>Subject: <input type="text" name="subject"><br /></center> <br> <center>Message: <br/><textarea name="message"> </textarea><br /></center> <center> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </center> </form> </body> </html> 

What should I do now?

+5
source share
3 answers

You need to use an SMTP client (for example, the one located in Javamail ) to send postmaster@example.com to dest@gmail.com from your domain. You should put the Javamail JAR on your CLASSPATH and type code in this question .

Since Java programming in JSP is not recommended, you are better off using Servlet for this.

0
source

Since your action is set to mail.jsp, create this JSP inside JSP too, you can use scripts like

 <% // Use Java Mail API to send email here %> Some points 1. Get the information from request e.grequest.getParameter("subject") 2. Explore Java Mail API and find out about SMTP server available for you. If not available then you can also Google SMTP Server (Do bit google on it) 3. I think your problem is how to put Java Code in JSP, so as mentioned above use scriptlets. 

The best way to do this is to create a servlet and in your action attribute of the form specify the URL of this servlet. And after sending email from this servlet, you can forward any other JSP or the same one with the message (sent by email).

If you are new to JSP, this should help, but if you are new to Java, tell me that I can send source code that can send email using the parameters of your form.

0
source

Check out the JavaBrains video tutorial, this is great for me.
There will be information on how you can send data from the form in the JSP to the servlet and how you can do something with this data.
http://javabrains.koushik.org/p/jsps-and-servlets.html

0
source

All Articles