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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:38:50+00:00 2026-06-16T00:38:50+00:00

This SHOULD be pretty simple, but day 2 I cannot figure it out. I

  • 0

This SHOULD be pretty simple, but day 2 I cannot figure it out. I have a login.jsp which contains a routine login form. I want to essentially post to itself, and have the controller take action based on whether the form is being hit for the first time or if it is being submitted with data.

What’s happening is that the blank form loads fine, but upon submission of a username and password I get an HTTP 404.

<div id="messageBox">${loginMessage}</div>

<form id="form1" name="form1" method="post" action="/do/login" onsubmit="return validateForm()">
<table>
    <tr>
        <td>Username:</td>
        <td><input name="username" type="text" size=30 value="" /></td>
    </tr>
    <tr>
        <td>Password:</td>
        <td><input name="password" type="password" size=30 value="" /></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="submit" value="Login" /></td>
    </tr>
</table>
</form>

These are my controller mappings:

@RequestMapping(value = "/login", method=RequestMethod.POST)
public ModelAndView login(@RequestParam("username") String username, @RequestParam("password") String password, Model model) {
    if (username == null || password == null) {
        // User has not specified all required fields
        String loginMessage = "Please complete all fields";
        return new ModelAndView("login", "loginMessage", loginMessage);
    } else {
        // User has specified username and password
        // Attempt authentication 
        Login login = new Login();
        isAuthenticated = login.authenticate(username, password);

        if (isAuthenticated) {
            // Authentication succeeded, return the options page
            return viewOptions(model);
        } else {
            // Authentication failed, return the login page
            String loginMessage = "Authentication failed";
            return new ModelAndView("login", "loginMessage", loginMessage);
        }
    }
}

@RequestMapping(value = "/login", method=RequestMethod.GET)
public ModelAndView login(Model model) {
    // Blank login screen
    String loginMessage = "&nbsp;";
    return new ModelAndView("login", "loginMessage", loginMessage);
 }

Edit after much pounding on this …
I’ve also tried the following approach, which gets the same result…

 <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<div id="messageBox">${loginMessage}</div>

<form:form modelAttribute="loginForm" id="form1" name="form1" method="post" action="/do/authenticate" onsubmit="return validateForm()">
<table>
    <tr>
        <td><form:label path="username">Username:</form:label></td>
        <td><form:input path="username" /></td>
    </tr>
    <tr>
        <td><form:label path="password">Password:</form:label></td>
        <td><form:input path="password" /></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="submit" value="Login" /></td>
    </tr>
</table>
</form:form>

With a LoginForm backing object:

package com.cloudfordev.spring3;

public class LoginForm {

private String username;
private String password;

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}
}

And the following controller:

@Controller
@SessionAttributes
public class VMGeneratorController {

@ModelAttribute("loginForm")
public LoginForm getLoginFormObject() {
    return new LoginForm();
}

@RequestMapping(value = "/viewoptions", method = RequestMethod.GET)
public ModelAndView viewOptions(Model model) {

    Menu menu = new Menu();
    String optionsPage = menu.draw();
    return new ModelAndView("options", "body", optionsPage);
}

@RequestMapping(value = "/authenticate", method = RequestMethod.POST)
public ModelAndView login(@ModelAttribute("loginForm") LoginForm loginForm, BindingResult result) {
    boolean isAuthenticated = false;

    String username = loginForm.getUsername();
    String password = loginForm.getPassword();

    if (username == null || password == null) {
        // User has not specified all required fields
        String loginMessage = "Please complete all fields";
        return new ModelAndView("login", "loginMessage", loginMessage);
    } else {
        // User has specified username and password
        // Attempt authentication 
        Login login = new Login();
        isAuthenticated = login.authenticate(username, password);

        if (isAuthenticated) {
            // Authentication succeeded, return the options page
            String loginMessage = "Success";
            return new ModelAndView("login", "loginMessage", loginMessage);
        } else {
            // Authentication failed, return the login page
            String loginMessage = "Authentication failed";
            return new ModelAndView("login", "loginMessage", loginMessage);
        }
    }
}

@RequestMapping(value = "/login", method=RequestMethod.GET)
public ModelAndView login(Model model) {
    // Blank login screen
    String loginMessage = "&nbsp;";
    return new ModelAndView("login", "loginMessage", loginMessage);
 }
}
  • 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-16T00:38:51+00:00Added an answer on June 16, 2026 at 12:38 am

    Maybe you need to take into account the web-app context-root. Assuming your webapp is placed on http://mydomain.com/myapp, then you need to post to /myapp/do/login instead of just /do/login ?

    If above is not the solution, then you need to trace your spring context.xml, web.xml, app server specifix config (tomcat context.xml / jboss-web.xml) etc. to ensure you’ve get all the plumbing in place

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

Sidebar

Related Questions

This should be pretty simple, but I am not figuring it out. I have
This should be pretty simple, but I am new at LINQ. I have a
This should be pretty simple but it's not working. I have a file underneath
This should be pretty simple, but I can't seem to get it. I have
So this should be pretty simple, but it isn't working. I have the following
I think this should be pretty simple, but I'm a SQL newb. I have
this should be really simple but I can just not figure it out at
This feels like it should be pretty simple, but not much seems to be
This should be a pretty straightforward question. I have the following code, which forms
This should be simple, but I'm getting confused. I have a parent/child tables -

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.