Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7985285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:30:40+00:00 2026-06-04T11:30:40+00:00

I have mapped a servlet and a jsp form. Once the form the is

  • 0

I have mapped a servlet and a jsp form. Once the form the is filled out I should get a confirmation page with the summary of what was filled in and an email (remote using gmail) should be sent but so far nothing happens, not even error messages. It loads back to the jsp file where the registration form is. Any ideas why this is happening?

There is no DB interaction in the process at all.

This is the Servlet:

package eBooks.controller;

import eBooks.business.User;
import eBooks.util.MailUtil;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.mail.MessagingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpSession;

public class ContactServlet extends HttpServlet{

protected void doPost(HttpServletRequest request,
                      HttpServletResponse response)
                      throws ServletException, IOException
{
    // get parameters from the request
    String fName = request.getParameter("fName_contact");
    String lName = request.getParameter("lName");
    String emailAddress = request.getParameter("emailAddress");
    String subject = request.getParameter("subject_contact");
    String messageArea = request.getParameter("messageArea");

    // Create a user object and store the object
    User user = new User(fName, lName, emailAddress, subject, messageArea);

    HttpSession session = request.getSession();
    session.setAttribute("user", user);

    // send email to user

    String to = emailAddress;
    String from = "somemail@gmail.com";
    String emailSubject = subject;
    String body = "Dear " + fName + ", \n\n"+
            "Thanks for contacting us. This is a confirmation to inform you that"
            + "we received your message.\n\n"
            + "Our team is reviewing your message and we will get back to you as soon"
            + "as possible. \n\n"
            + "Regards,\n\n"
            + "Matt \n"
            + "CEO";
    boolean isBodyHtml = false;

    try
    {
        MailUtil.sendMail(to, from, emailSubject, body, isBodyHtml);
    }
    catch(MessagingException e)
    {
        String errorMessage =
              "Error Unable to send email. " +
                "Check your Server (Glassfish) logs for details.<br/>" +
                "Note: You may need to configure your system again.<br/>"+ 
              "Error Message: " + e.getMessage();
        request.setAttribute("errorMessage", errorMessage);
        this.log(
                "Unable to send email. \n" +
                "Here is the email you tried to send \n"+
                "====================================\n"+
                "To:" + emailAddress + "\n"+
                "FROM: " + from + "\n" +
                "SUBJECT: " + subject + "\n"+
                "\n" +
                body + "\n\n");
    }

    // forward request and response to JSP page
    String url = "/WEB-INF/view/confirmation.jsp";
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
    dispatcher.forward(request, response);
}

}

This the contact form:

 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


    <%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <head>


        <link rel="stylesheet" type="text/css" href="css/stylesheet.css">

        <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

        <title>Contact</title>

    </head>

    <body>

    <div id="page-container">

<c:import url="/WEB-INF/includes/main-nav.jspf"/>

            <div id="header-content">     

                <h1> [ Contact ] </h1>
                <p>&nbsp;</p>
                <p>&nbsp;</p>

                <h2>Share your thoughts with us:</h2>


                <form action="contactEmail" method="post">

                        <p class="name">
                                <input type="text" name="fName" id="fName"
                                       value ="${User.fName}"/>

                                <label for="fName">First Name</label>
                        </p>

                        <p class="name">
                                <input type="text" name="lName" id="lName"
                                    value ="${user.lName}"/>
                                <label for="lName">Last Name</label>
                        </p>

                        <p class="email">
                                <input type="text" name="emailAddress" id="emailAddress"
                                    value="${user.emailAddress}"/>
                                <label for="emailAddress">E-mail</label>
                        </p>

                        <p class="web">
                                <input type="text" name="subject" id="subject"
                                       value="${user.subject}"/>
                                <label for="subject">Subject</label>
                        </p>

                        <p class="text-message">
                            <label for="messageArea">Your message: </label><br>
                            <br>                        
                            <textarea name="messageArea" id="messageArea" 
                                     >${user.message}</textarea>

                        </p>

                        <p class="submit">
                                <input type="button" 
                                       onClick="validate(this.form)" value="Submit">                
                        </p>

                    </form>

                <p>&nbsp;</p>


                <script language="JavaScript">
                    function validate(form){
                        if(form.fName.value==""){
                            alert("Please fill your first name");
                            form.fName.focus();
                        }
                        else if(form.lName.value==""){
                            alert("Please fill your last name");
                            form.lName.focus();
                        }
                        else if(form.subject.value==""){
                            alert("Please fill the subjetct");
                            form.subject.focus();                      
                        }
                        else if (form.messageArea.value==""){
                            alert("The message cannot be empty");
                            form.text_message_area.focus();
                        }

                        else{
                            form.submit();
                        } 
                    }
                </script>


            </div>


            <div id="content-assist">

                <div class ="padding">

                    <h2>We are located at:</h2>

                    <p>153 West 139th Street New York, NY<br>


                    </p>
                        <p>We are currently undergoing a 'face lift', so if you have any questions or would like more information about the services we provide please feel free to contact us.</p>

                    <h2>Give us a call:</h2>
                        <p>Phone:   212- 470-5024<br />
                        Fax:     (212) xxx xxxx<br />
                        Email:   <a href="mailto:info@noemailLuistest.com">info@LuisDomainTest.com</a><br />
                        ZIP: 10030, New York, USA</p>
                        <p><a href="contact.jsp">More contact information…</a></p>


                </div>


            </div>


    <c:import url="/WEB-INF/includes/footer.jspf"/>

This is the confirmation jsp:

 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">      

        <link rel="stylesheet" type="text/css" href="css/stylesheet.css">

        <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

        <title>Dashboard</title>
    </head>
    <body>

<div id="page-container">

    <c:import url="/WEB-INF/includes/main-nav.jspf"/>


    <div id="confirmation-top">     

            <h2>[ Confirmation ]</h2>


        </div>


        <div id="confirmation">     

            <h2> Awesome! We got your message </h2>

            <p>Thanks for contacting us. Your message has been submitted and it
            will be reviewed by our specialist in the order in which it was received.</br>
            <br>    

            A confirmation email has been sent to ${sessionScope.user.emailAddress} </p>

            <form action="index.jsp">
                <input type="submit" value="/index.jps" name="home_btn" />
            </form>

                <p>
                    <i>${requestScope.errorMessage}</i>
                </p>

            <br>
        </div>

    <c:import url="/WEB-INF/includes/footer.jspf"/>

This is the emailUtil:

    package eBooks.util;



import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Message;
import javax.mail.Address;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailUtil {

    //private static String mailhost = "smtp.gmail.com";

    public static void sendMail(String to, String from, String body, 
                                String subject, boolean bodyIsHtml)
                                throws MessagingException
    {

        // 1 - get session 
        Properties props = new Properties();
        props.put("mail.transport.protocol", "smtps");
        props.put("mail.smtps.host", "smtp.gmail.com");
        props.put("mail.smtps.port", 465);
        props.put("mail.smtps.auth", "true");
        props.put("mail.smtps.quitwait", "false");
        Session session = Session.getDefaultInstance(props);
        session.setDebug(true);

        // 2 - create a message
        Message message = new MimeMessage(session);
        message.setSubject(subject);
        if(bodyIsHtml)
            message.setContent(body, "text/html");
        else
            message.setText(body);

        // 3 - address the message
        Address fromAddress = new InternetAddress(from);
        Address toAddress = new InternetAddress(to);
        message.setFrom(fromAddress);
        message.setRecipient(Message.RecipientType.TO, toAddress);

        // 4 - send the message
        Transport transport = session.getTransport();
        transport.connect("somemail2@gmail.com", "password123");
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
    }

}

This is the servlet xml:

    <!-- the definition fo r the servlets -->
<servlet>
    <servlet-name>ContactServlet</servlet-name>
    <servlet-class>eBooks.controller.ContactServlet</servlet-class>
</servlet>
<!-- the mapping for the servlets -->
<servlet-mapping>
    <servlet-name>ContactServlet</servlet-name>
    <url-pattern>/WEB-INF/view/contactEmail</url-pattern>
</servlet-mapping>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:30:41+00:00Added an answer on June 4, 2026 at 11:30 am

    Have you checked whether servlet is being called or not ?

    The problem lies here
    <form action="contactEmail" method="post">
    and your mapping says
    <url-pattern>/WEB-INF/view/contactEmail</url-pattern>

    Try changing

    <url-pattern>/contactEmail</url-pattern>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my web.xml page I have the 404 error mapped to a jsp page
I m able to get values using JPA when i have only mapped one
I realize that when you submit the form in a jsp, in the mapped
When you use JSF, you'll have the controller servlet javax.faces.webapp.FacesServlet that will be mapped
I have a servlet which handles a multipart form post. The post is actually
How is this achieved, I have everything mapped from / to the dispatcher Servlet
I have mapped the database in the edmx file from the database. Now how
I have mapped a network drive to a computer in my home network. Now
Two Windows processes have memory mapped the same shared file. If the file consists
I have a table called Person which I have already mapped in hibernate I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.