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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:59:42+00:00 2026-06-07T14:59:42+00:00

I have a form in which there is a text field. The user inputs

  • 0

I have a form in which there is a text field. The user inputs the email address in the text field, and when the user submits the form, the Action class finds the uid of the user from the Users table and displays the uid on the JSP page as a message with <s:actionmessage/>. I am getting an IndexOutOfBoundsException.

My JSP form is:

<s:form action="okadddqs" method="post" cssClass="text">

   <s:textfield label="Your Email address " name="email"/>
   <s:submit value="Find Uid"/>
 </s:form>

The code for the Action class is:

package com.rambo.action;

import beans.Users;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.hibernate.Session;

/**
 *
 * @author ROMO
 */
@ManagedBean
@SessionScoped
public class NewQuestion extends ActionSupport {

    private String email;

    private List<Users> ul = new ArrayList<Users>();

    public List<Users> getUl() {
        return ul;
    }

    public void setUl(List<Users> ul) {
        this.ul = ul;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
/* i have used many where the getUid() and getEmail() even in the error and messages to find what the value it is getting on error.  */
    @Override
    public String execute() throws Exception {
        Session session = null;
        int d;
        try {
            session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            try {
                ul = (List<Users>) session.createQuery("from Users c where c.email = '" + getEmail() + "'");
                if (!ul.isEmpty()) {
                    d = ul.get(0).getUid();
                } else {
                    this.addActionError("Oops. Sorry. You are Not Allowed now. Please Try Again Later." + getEmail() + ","+ ul.get(0).getUid());
                    session.close();
                    return ERROR;
                }
            } catch (Exception e) {
                this.addActionError("Oops. There was an error." + getEmail() + ","+ ul.get(0).getUid());
                session.close();
                return ERROR;
            }
            session.getTransaction().commit();
        } catch (Exception e) {
            this.addActionError("Oops. An Error Encountered...! Email address " + getEmail() + ","+ ul.get(0).getUid()+" not registered. Try with your new email address.");
            session.close();
            return ERROR;
        }
        this.addActionMessage("Your Uid is : " + ul.get(0).getUid());
        return SUCCESS;
    }

   @Override
    public void validate() {
       if ( "".equals(getEmail()) || getEmail() == null ) {
            this.addActionError("Email is Compulsory to input..!" + getCname());
        } else if (getEmail().indexOf("@") < 0 || getEmail().indexOf(",") > 0 || getEmail().indexOf(".") < 0 || lastEmailFieldTwoCharsOrMore(getEmail()) == false) {
            this.addActionError("Please Input a valid email address." + getCname());
        }
    }
}

when i remove all the try catch blocks i get the exception as :

java.lang.ClassCastException: org.hibernate.impl.QueryImpl cannot be cast to java.util.List

I have done the beans and mapping of tables properly with POJO. Can someone point out the error? I am using Hibernate with Struts.

  • 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-07T14:59:45+00:00Added an answer on June 7, 2026 at 2:59 pm

    The following line in your code is incorrect:

    ul = (List<Users>) session.createQuery(
        "from Users c where c.email = '" + getEmail() + "'"
    );
    

    createQuery returns back a query object. If you want the results of that query, use Query.list().

    ul = (List<Users>) session.createQuery(
        "from Users c where c.email = '" + getEmail() + "'"
    ).list();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which takes a couple of text field inputs and then
I have an application in which there is a form which I want to
I have a form where there are 6 items, each of which can be
I have a form which has three inputs when the page loads -- 2
I have a form with text inputs and file inputs; the text fields are
I have an ASP.NET form that takes input from a user. There's a Submit
I have a contact form in my flash file with name/email/message fields which a
We have a browser test page which is used to diagnose user problems. There
In index.php I have a form and in the form a text field: <form
I have a php form which saves these values to the database: id rand

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.