0

My jsp page consists of a form that takes in an email address. I then use java to check if my postgresql database already contains that email address. Right now my servlet just redirects the user back to the Registration page if the email address already exists.

What I am trying to do is write an error message on the form "The email address you entered already exists" with java. I haven't figured out how to do it.

Is there some way I could do this with jQuery form validation? I am using that right now for required fields.

John
  • 2,820
  • 3
  • 30
  • 50
Dylan
  • 499
  • 1
  • 10
  • 21

1 Answers1

1

Here you need to pass information from servlet to JSP.

To Pass parameter from servlet to JSP or vice versa.

Use Session to pass value from one page to another (here).

In Servlet

request.getSession().setAttribute("email", "exist/notexist");

In JSP

Make a blank div just beside the email textbox and set its content based on the value of String s1 which is set from session.getAttribute("key") method.

    <%! String s1 = ""; %>
    <% s1  = (String) session.getAttribute("email");%>
    <% if(s1.equals("exist")){ %>
    <div class="besideemailbox" style="color : red">Email Already exist</div>
    <% }else if(s1.equals("something")){ %>
    <div class="besideemailbox" style="color : green">ok or a tick</div>
    <% } %>
Community
  • 1
  • 1
rhitz
  • 1,892
  • 2
  • 21
  • 26
  • When I do this, the error message doesn't go away when I refresh the page though. I tried terminating the session, but that doesn't work. I'm new to this session stuff. – Dylan Aug 02 '15 at 22:21
  • try removing the attribute from the session after you have shown your alert. – Dibyajyoti Mishra Mar 05 '23 at 13:26