0
String transportVehicle = "";
    String firstname = request.getParameter("fname");
    String lastname = request.getParameter("lname");
    String email = request.getParameter("email");
    String password = request.getParameter("password");
    String number = request.getParameter("phone");
    int phone = Integer.parseInt(number);
    String gender = request.getParameter("gender");
    String[] vehicle = request.getParameterValues("vehicle");
    String country = request.getParameter("country");
    String city = request.getParameter("city");
    List<String> errors = new ArrayList<String>();
    User user = new User();
    user.setFname(firstname);
    user.setLname(lastname);
    user.setEmail(email);
    user.setPassword(password);
    user.setPhone_no(phone);
    user.setGender(gender);
    for (int i = 0; i < vehicle.length; i++) {
        transportVehicle += vehicle[i] + "";
    }
    user.setVehicles(transportVehicle);
    user.setCountry(country);
    user.setCity(city);

    Map<String, String> message = new HashMap<String, String>();
    request.setAttribute("message", message);

    if (firstname.equals("") || firstname == null || firstname.trim().isEmpty()) {
        message.put("fname", "enter the firstname");
    }
    if (lastname.equals("") || lastname == null || lastname.trim().isEmpty()) {
        message.put("lname", "enter the lastname");
    }
    if (email.equals("") || email == null || email.trim().isEmpty()) {
        message.put("email", "enter the email");
    }
    if (password.equals("") || password == null || password.trim().isEmpty()) {
        message.put("password", "enter the password");
    }
    if (number.equals("") || number == null || number.trim().isEmpty()) {
        message.put("phone", "enter the number");
    }
    if (country.equals("") || country == null || country.trim().isEmpty()) {
        message.put("country", "enter the country");
    }
    if (city.equals("") || city == null || city.trim().isEmpty()) {
        message.put("city", "enter the city");
    }
    if (!message.isEmpty()) {
        request.getRequestDispatcher("index.html").forward(request, response);
    } else {;

How do I send the list to the jsp page and display the error in display page how should i do that.please help me out? any help would be kind? In this code i have created a maps class which is used for the errors. how should i put my errors in jsp page.how am i supposed to that.any help will be appreciated.

ayushs27
  • 97
  • 1
  • 8

1 Answers1

0

You have allmost achieve what you want to do. The map is available in the jsp with this :

request.setAttribute("message", message);

You only need to iterate over the map and show the message. You have an example here : How to loop through a HashMap in JSP?.

Using jstl you have to do something like this :

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:forEach items="${message}" var="entry">
    <span class="errorMessage">${entry.value}</span>
</c:forEach>

With custom CSS errorMessage to style your message.

marojbor
  • 191
  • 10