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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:59:38+00:00 2026-06-15T16:59:38+00:00

I want to just run a method in a javaBean class (its not a

  • 0

I want to just run a method in a javaBean class (its not a getter or setter method) it takes 2 parameters (username , password) and returns a boolean (after varifing it from the database(seperate DAO class)).

then I want to make a a decision depending on that boolean value to show some text or redirect page. how can i do it.? do i need JSTL or jsp:action (useBean and set/get property) tag or would be enough?

WITHOUT SCRIPTLETS or java code in .jsp page. niether any framworks like struts or spring
any practical code?

index.jsp

  <%@page contentType="text/html" pageEncoding="UTF-8"%>
  <!DOCTYPE html>
  <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Open-Pages</title>
      </head>
      <body>
      <form method="post" action="/open-pages/comments.jsp">
        User Name: <input type="text" name="userName">
        <br />
        Password: <input type="password" name="password">
        <input type="submit" value="submit">
        <input type="reset" value="reset">
      </form>
      </body>
  </html>

comments.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <%
//         out.println(request.getParameter("userName"));
//         out.println(request.getParameter("userName"));
    %>

    <jsp:useBean id="verifyUser" class="entry.UserBean" scope="page" />
    <jsp:setProperty name="verifyUser" property="userName" param="userName" />
    <jsp:setProperty name="verifyUser" property="password" param="password" />

    <jsp:getProperty name="verifyUser" property="userName" />
    <jsp:getProperty name="verifyUser" property="password" />


    </body>
</html>

UserBean.java

      /*
      * To change this template, choose Tools | Templates
      * and open the template in the editor.
      */
      package entry;

      import java.io.Serializable;


      /**
      *
      * @author user1
      */
      public class UserBean implements Serializable{
      private String userName;
      private String password;
      private boolean validUser;

      /**
      * @return the userName
      */
      public String getUserName() {
          return userName;
      }

      /**
      * @param userName the userName to set
      */
      public void setUserName(String userName) {
          this.userName = userName;
      }

      /**
      * @return the password
      */
      public String getPassword() {
          return password;
      }

      /**
      * @param password the password to set
      */
      public void setPassword(String password) {
          this.password = password;
      }




      public boolean getValidUser(String user, String password) {
          if(entry.userAuthDAO.verifyUserPass(user,password)){
        return true;
        }else {
        return false;
        }
      }


      public void setValidUser(boolean validUser) {
          this.validUser = validUser;
      }
      }

UserAuthDAO

      package entry;


      import entry.Constants;
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.util.logging.Level;
      import java.util.logging.Logger;

      /*
      * To change this template, choose Tools | Templates
      * and open the template in the editor.
      */

      /**
      *
      * @author user1
      */
      public class userAuthDAO {

      static String authUser = "select userName, password "
              + "from users "
              + "where userName = ? and password = ?";
      public static boolean verifyUserPass(String userName, String password){


          try {
          Connection con = DriverManager.getConnection(Constants.DBHost, userName, password);
          PreparedStatement pStmt = con.prepareStatement(authUser);

          pStmt.setString(1,userName);
          pStmt.setString(2, password);

          ResultSet rs = pStmt.executeQuery();
          String rsUserName = null;
          String rsPassword = null;
          if(rs.next()){
              rsUserName = rs.getString("userName");
              rsPassword =  rs.getString("password");    
          }

          con.close();

          if (rsUserName.equals(userName) && rsPassword.equals(password)){
              return true;
          }



        } catch (SQLException ex) {
            Logger.getLogger(userAuthDAO.class.getName()).log(Level.SEVERE, null, ex);

        }
        return false; 
      }

      }
  • 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-15T16:59:38+00:00Added an answer on June 15, 2026 at 4:59 pm

    Don’t do that in a JSP. That’s not what JSPs are for. They’re view components, and should be used to generate HTML markup.

    Do that from a servlet, or an action of your preferred MVC framework. Once the servlet or action has the result, then dispatch to a JSP or redirect.

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

Sidebar

Related Questions

I just want that my program or method should run at specific date and
I just want to run a certain method for 20 seconds when user presses
I just want to run the HelloServlet by the url: http://localhost:8080/HelloServlet . but it
I just want to find out how to run two WPF windows (one in
When I run this, an empty title bar is displayed. I just want to
I have a Thread running in a Service... its run method looks something like
I want just get Image( .JPG , .PNG , .Gif ) File from my
With php file_get_contents() i want just only the post and image. But it's get
I'm working on an app to block GtalkService. I want just use iptables for
I just want to ask if anybody has done something like this. Basically, it's

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.