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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:16:43+00:00 2026-06-10T15:16:43+00:00

I’m new to Spring MVC framework, having some trouble with basic URL mapping using

  • 0

I’m new to Spring MVC framework, having some trouble with basic URL mapping using two different controllers. I’m using @Controller and @RequestMapping.

The following results in 404 error for both /people and /accounts.

Here is my Spring MVC 3.1 setup:

index.jsp

<!DOCTYPE html>
<html>
<head>
    <title>t-diggity</title>
</head>
<body>
    <h1>integration</h1>
    <a href="/people/">Contact List</a><br>
    <a href="/accounts/">Account List</a><br>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://java.sun.com/xml/ns/javaee"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     version="2.5">

<display-name>t-diggity</display-name>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
            <param-name>contextAttribute</param-name>
            <param-value>org.springframework.web.servlet.FrameworkServlet.CONTEXT.spring</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

<servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/people/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/assets/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/accounts/*</url-pattern>
    </servlet-mapping>

</web-app>

controller # 1: PersonController.java

@Controller
@RequestMapping("/people/")
public class PersonController {

    @Autowired
    private PersonService personService;

    @RequestMapping("/")
    public String listPeople(Map<String, Object> map) 
    {
        map.put("person", new Person());
        map.put("peopleList", personService.listPeople());
        return "people";
    }

    @RequestMapping(value = "/addPerson", method = RequestMethod.POST)
    public String addPerson(@ModelAttribute("person") Person person, BindingResult result
    {
        personService.addPerson(person);
        return "redirect:/people/";
    }

    @RequestMapping("/delete/{personId}")
    public String deletePerson(@PathVariable("personId") String personId) 
    {
        personService.removePerson(personId);
        return "redirect:/people/";
    }
}

controller #2: AccountController.java

@Controller
@RequestMapping("/accounts")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/")
    public String listAccounts(Map<String, Object> map) 
    {
        map.put("account", new Account());
        map.put("accountList", accountService.listAccounts());
        return "accounts";
    }

    @RequestMapping(value = "/addAccount", method = RequestMethod.POST)
    public String addPerson(@ModelAttribute("account") Account account, 
                            BindingResult result) 
    {
        accountService.addAccount(account);
        return "redirect:/accounts/";
    }

    @RequestMapping("/delete/{accountId}")
    public String deleteAccount(@PathVariable("accountId") String accountId) {
        accountService.removeAccount(accountId);
        return "redirect:/accounts/";
    }

}

I am hoping my error is a minor one, I’m new to URL mapping so it likely is minor… I’d appreciate any coaching, thanks in advance.

  • 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-10T15:16:45+00:00Added an answer on June 10, 2026 at 3:16 pm

    Change index.jsp to:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>t-diggity</title>
    </head>
    <body>
        <h1>integration</h1>
        <a href="<c:url value="/people/"/>">Contact List</a><br>
        <a href="<c:url value="/accounts/"/>">Account List</a><br>
    </body>
    </html>
    

    The anchor URLs were not including the root context. The c:url tag will handle this for you.

    Change the web.xml mapping to:

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    

    There is usually no need to map your controllers separately if everything in your web app is controlled by Spring MVC.

    And map your @Controllers like this:

    @Controller
    @RequestMapping("/people")
    public class PersonController {
    
        @RequestMapping("/")
        public String listPeople(Map<String, Object> map) {
            ...
            return "people";
        }
    
    }
    

    All I’ve done here is to lose the trailing / on the @RequestMapping for /people.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported

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.