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 1037995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:55:09+00:00 2026-05-16T14:55:09+00:00

I’m creating registration page and I’ve done basic client side (JS) form validation. Now

  • 0

I’m creating registration page and I’ve done basic client side (JS) form validation.
Now I am to write server side validation.

What I have done is call request.getParameter():

String username = request.getParameter("username");

Then if the username input is not valid, I put error message to ArrayList:

ArrayList<String> errors = new ArrayList<String>();
errors.add("username is not valid");

Then, add the ArrayList object to session variable,

session.setAttribute("inputErrors", errors);

This way I can use logic to see if the ArrayList is not empty (i.e. there is an error),
redirect back to registration page and get the session value to display proper error message.

But I am wondering if using session this way is good way for handling error messages.
Since this operation only involves 2 pages: registration UI (regis.jsp) and the page that handles registration input validation and processing (process_regis.jsp) for instance.
My understanding of session is to be used across multiple pages mainly for logged-in user data.

please let me know if you need more clarification.

  • 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-05-16T14:55:10+00:00Added an answer on May 16, 2026 at 2:55 pm

    The server side session is been shared among all requests from the same client session. The session lives as long as the user accesses the site for the first time until the session is been expired (not used over 30 minutes (which is configureable)), or it is been explicitly invalidated. With your approach, open the same page in a new browser tab. You would still see the error messages while the form in the new page isn’t entered/submitted at all. This is not good for user experience.

    The normal practice is to store the error messages in the request scope and forward the request to the same page instead of redirecting to it. This is easy if you use a fullworthy Servlet class instead of a JSP file for processing and validating. E.g.

    /WEB-INF/register.jsp

    <form method="post" action="register">
        <p><label for="username">Username</label>
        <input type="text" id="username" name="username" value="${fn:escapeXml(param.username)}">
        <span class="error">${messages.username}</span>
        <p><label for="password">Password</label>
        <input type="password" id="password" name="password">
        <span class="error">${messages.password}</span>
        <p><label for="confirm">Confirm password <span class="required">*</span></label>
        <input type="password" id="confirm" name="confirm">
        <span class="error">${messages.confirm}</span>
        <p><input type="submit" value="Register">
        <p>${messages.result}</p>
    </form>
    

    com.example.RegisterServlet

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/register.jsp").forward(request, response);
    }
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map<String, String> messages = new HashMap<String, String>();
        request.setAttribute("messages", messages); // Will be available by ${messages}.
    
        String username = request.getParameter("username");
        if (username == null  || username.trim().isEmpty()) {
            messages.put("username", "Please enter username");
        }
    
        // ...
    
        request.getRequestDispatcher("/WEB-INF/register.jsp").forward(request, response);
    }
    

    Map this servlet as follows in web.xml:

    <servlet>
        <servlet-name>registerServlet</servlet-name>
        <servlet-class>com.example.RegisterServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>registerServlet</servlet-name>
        <url-pattern>/register</url-pattern>
    </servlet-mapping>
    

    Open it by http://example.com/context/register and go ahead.

    See also

    • Beginning and intermediate JSP/Servlet tutorial
    • DAO Tutorial – Use in JSP/Servlet (covers "Register User" use case)
    • Servlet instantiation and session variables
    • Hidden features of JSP/Servlet
    • How to avoid Java code in JSP
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a text area in my form which accepts all possible characters from
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has

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.