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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:25:09+00:00 2026-06-10T12:25:09+00:00

i am getting an error message: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.ClassCastException:

  • 0

i am getting an error message:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.ClassCastException: java.lang.Object cannot be cast to com.crimetrack.business.Login

Login.java

public class Login {

    private String userName;
    private String password;
    private boolean loggedin;

    public Login(){};

    /**
     * @return the loggedin
     */
    public boolean isLoggedin() {
        return loggedin;
    }

    /**
     * @param loggedin the loggedin to set
     */
    public void setLoggedin(boolean loggedin) {
        this.loggedin = loggedin;
    }

    /**
     * @param userName
     * @param password
     */
    public Login(String userName, String password) {
        this.userName = userName;
        this.password = password;
    }

    /**
     * @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;
    }

}

@Controller
public class AuthenticationController {

    private final Logger logger = Logger.getLogger(getClass());

    private AuthenticationManager authenticationManager;
    private Login login = new Login();

    String message = "Congrulations You Have Sucessfully Login";
    String errorMsg = "Login Unsucessful";

    @RequestMapping(value="login.htm")
    public ModelAndView onSubmit(Object command) throws ServletException {

        String userName = ((Login)command).getUserName();
        String password = ((Login)command).getPassword();

        login.setUserName(userName);
        login.setPassword(password);

        logger.info("Login was set");

        logger.info("the username was set to " + login.getUserName());
        logger.info("the password was set to " + login.getPassword());

        if (authenticationManager.Authenticate(login) == true){
            return new ModelAndView("main","welcomeMessage", message);
        }

        //return new ModelAndView("main","welcomeMessage", message);
        return new ModelAndView("login","errorMsg", "Error!!!");
    }

}
  • 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-10T12:25:11+00:00Added an answer on June 10, 2026 at 12:25 pm

    Try this solution:

    JSP

    <form:form action="yourUrl" modelAttribute="login" method="POST">
    <% ... %>
    </form:form>
    

    Controller

    // your method that prints the form
    public ModelAndView onGet(@ModelAttribute Login login) {
        // return ...
    }
    
    @RequestMapping(value="login.htm")
    public ModelAndView onSubmit(@ModelAttribute Login login) {
        String userName = login.getUserName();
        String password = login.getPassword();
        // ...
    }
    

    Explanation

    The annotation @ModelAttribute does exactly the same as model.addAttribute(String name, Object value). For example, @ModelAttribute Login login is the same as model.addAttribute("login", new Login());.

    That said, with the onGet method, you passing such an object to your view. Thanks to the attribute modelAttribute="login", the tag <form:form> will look into the model’s list of attributes to find one which name is login. If it doesn’t find, an exception is thrown.

    Then, that’s the magic part: with the tag <form:input path="userName" />, Spring MVC will automatically set the property userName of the bean which is in the modelAttribute="login" attribute, i.e. in your case, login. If you had put something like <form:input path="wtf" />, it would have thrown an exception, because the bean Login doesn’t have such a property.

    So, finally, on your onSubmit method (thanks once again the to annotation @ModelAttribute), you can access to the login bean, previously autobinded by Spring MVC.

    Note

    I personally (almost) never use a ModelAndView instance, but proceed as follow:

    // the methods can have the name you want
    // not only onGet, onPost, etc. as in servlets
    
    @RequestMapping("url1.htm")
    public String loadAnyJsp(@ModelAttribute Login login) {
        return "path/to/my/views/login";
    }
    
    @RequestMapping("url2.htm")
    public String redirectToAnotherController(@ModelAttribute Login login) {
        return "redirect:url1.htm";
    }
    

    The path to the JSP is specified within your web.xml file, for example:

    ...
    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver" p:favorPathExtension="true" p:favorParameter="true" p:ignoreAcceptHeader="true" p:defaultContentType="text/html">
        <description>Depending on extension, return html with no decoration (.html), json (.json) or xml (.xml), remaining pages are decoracted</description>
        <property name="mediaTypes">
            <map>
                <entry key="xml" value="application/xml" />
                <entry key="json" value="application/json" />
                <entry key="html" value="text/html" />
                <entry key="action" value="text/html" />
            </map>
        </property>
        <property name="defaultViews">
            <list>
                <bean class="org.springframework.web.servlet.view.xml.MarshallingView" p:marshaller-ref="xstreamMarshaller" />
                <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
            </list>
        </property>
        <property name="viewResolvers">
            <list>
                <bean id="nameViewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver">
                    <description>Maps a logical view name to a View instance configured as a Spring bean</description>
                </bean>
                <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/views/" p:suffix=".jsp" />
            </list>
        </property>
    </bean>
    ...
    

    You should read the doc to get more information (cf. 16.5 Resolving views).

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

Sidebar

Related Questions

I'm getting this error. my web.xml has this <servlet> <servlet-name>springweb</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/web-application-config.xml</param-value>
Am getting following error message on calling WCF service: The formatter threw an exception
I am getting an exception saying : java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required When
I am getting the following error message: org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed I
I'm trying to use util-constant for ioc but I'm getting the following error message:
Help! I'm getting this error when trying to connect using JAX-WS webservice call: java.lang.NoClassDefFoundError:
I'm getting the following error message when I try to start a spring web
I'm getting error messages for no reason in RAD 8: And the error message
Am getting this error message and matched my brackets and couldn't find anything wrong.
I'm getting this error message whiile running a Webservice I'm working on. it builds,

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.