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

  • Home
  • SEARCH
  • 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 8617955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:59:41+00:00 2026-06-12T05:59:41+00:00

How can I validate password with confirm password in login.jsp and only if equal,

  • 0

How can I validate password with confirm password in login.jsp and only if equal, then redirect to success.jsp which displays Welcome #{beans.username}.

  • 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-12T05:59:43+00:00Added an answer on June 12, 2026 at 5:59 am

    Just implement a Validator the usual way. Validation should surely not be done in the action method as others suggest/imply. If validation fails, then by default the action method just won’t be invoked and the same page will just be redisplayed with validation errors. You can pass the password field as <f:attribute> of the confirm password field so that the validator can get hold of its value for test.

    Here’s a kickoff example of the view:

    <h:inputSecret id="password" binding="#{passwordComponent}" value="#{bean.password}" required="true" />
    <h:message for="password" />
    
    <h:inputSecret id="confirm" required="#{not empty password.value}">
        <f:validator validatorId="confirmPasswordValidator" />
        <f:attribute name="passwordComponent" value="#{passwordComponent}" />
    </h:inputText>
    <h:message for="confirm" />
    

    and the validator:

    @FacesValidator("confirmPasswordValidator")
    public class ConfirmPasswordValidator implements Validator {
    
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            UIInput passwordComponent = (UIInput) component.getAttributes().get("passwordComponent");
            String password = (String) passwordComponent.getValue();
            String confirmPassword = (String) value;
    
            if (confirmPassword != null && !confirmPassword.equals(password)) {
                throw new ValidatorException(new FacesMessage(
                    FacesMessage.SEVERITY_ERROR, "Confirm password is not the same as password", null));
            }
        }
    
    }
    

    The message will appear in <h:message for="confirm">.

    Note that you only need to have the password as a property in the backing bean, not the confirm password.

    private String password;
    
    // Getter+setter.
    

    In the action method you can just return the navigation case outcome the usual way:

    public String login() {
        User user = userService.find(username, password); 
    
        if (user != null) {
            FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("user", user);
            return "success?faces-redirect=true";
        } else {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(
                FacesMessage.SEVERITY_WARN, "Unknown login, please try again.", null));
            return null;
        }
    }
    

    Since JSF 2.0 there’s no need for verbose navigation cases in faces-config.xml anymore as the other answer suggest.


    Unrelated to the concrete problem, why are you still sticking to the legacy JSP view technology? This has been deprecated since JSF 2.0 in favor of Facelets. Please consider migrating JSP to Facelets. Then you’ll be able to use among others the new JSF 2.0 <f:ajax> awesomeness and strong Facelets templating capabilities.

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

Sidebar

Related Questions

I want to write a function which can validate a given value (passed as
I am looking for a Java framework which can validate order of elements in
How can I validate a string using Regular Expressions to only allow alphanumeric characters
how can i validate a password with asp.net mvc dataanotation, the password must be
/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,8}/ This RegEx is supposed to validate a password, which should contain at least
You can validate a model object with EF 5 Code-First like that: var validationResult
I have vote and votedown tables for posts. I can validate uniqueness within the
Can I validate a form on button click without submitting the whole form using
How can i validate the text length of the element that has an attribute.
How can i validate content of a input box? that when a user for

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.