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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:44:24+00:00 2026-06-15T23:44:24+00:00

BACKGROUND I come from .NET background and Spring MVC is new to me. In

  • 0

BACKGROUND

I come from .NET background and Spring MVC is new to me. In general, I’m not great with Java, so please answer in a way that’s easy for even a Java newbie to understand.

PROBLEM

I am trying to build a simple CRUD controller. I am getting the main page working fine (View All), but then I keep getting 404 errors on pages where I am using @RequestParam to try map query string values to method parameters.

MAIN VIEW

<html>
    <head>
        <title>Users - KSC Technology & Sciences</title>
        <jsp:include page="../headParts.jsp" />
    </head>
    <body>
        <jsp:include page="../topMenu.jsp" />
        <div id="body" class="container-fluid">
            <div class="row-fluid">
                <div class="span3">
                    <jsp:include page="../leftMenu.jsp" />
                </div>
                <div class="span9">
                    <div class="row-fluid">
                        <a href="/users/create" class="btn btn-primary">Create</a>
                        <hr />
                        <table class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>User Name</th>
                                    <th>E-mail</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                <c:forEach var="row" items="${records}">
                                    <tr>
                                        <td><c:out value="${row.id}" /></td>
                                        <td><c:out value="${row.userName}" /></td>
                                        <td><c:out value="${row.email}" /></td>
                                        <td>
                                            <a href="/users/edit?id=${row.getId()}" class="btn">Edit</a>
                                            <a href="/users/delete?id=${row.getId()}" class="btn btn-danger">Delete</a>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <hr />
        <jsp:include page="../footer.jsp" />
    </body>
</html>

CONTROLLER

@Controller
public class UserController {

    @EJB(mappedName="java:global/KSC/UserService!com.ksc.services.UserService")
    private UserService service;

    @RequestMapping(value = "/users")
    public String index(ModelMap model) {
        model.addAttribute("records", service.findAll());
        return "user/index";
    }

    @RequestMapping(value = "/users/create")
    public String create(ModelMap model) {
        model.addAttribute("record", new KCSUser());
        return "user/edit";
    }

    @RequestMapping(value = "/users/edit")
    public String edit(ModelMap model, @RequestParam(value="id") String id) {
        int userId = Integer.parseInt(id);
        model.addAttribute("record", service.find(userId));
        return "user/edit";
    }

    @RequestMapping(value = "/users/delete")
    public String delete(ModelMap model, @RequestParam(value="id") String id) {
        int userId = Integer.parseInt(id);
        KCSUser user = service.find(userId);
        service.remove(user);

        return index(model);
    }
}

I can access the main view, but when clicking Edit (for example), then I get a 404. What am I doing wrong?

EDIT

Directory Structure:

enter image description here

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>/</welcome-file>
    </welcome-file-list>
</web-app>

dispatcher-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />

    <context:component-scan base-package="com.ksc.controllers" />
    <mvc:annotation-driven />
</beans>

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
</beans>

Now that I think about it, I did have to hack the web.xml and dispatcher-servlet.xml files a bit because the ones generated by Netbeans didn’t work.. so i copied it from some online source instead. I didn;t change the applicationContext.xml though and I see it is targetting Spring 2.5.. I’m confused.. can someone give me working config files for Spring 3.1? Maybe that’s the problem here?

EDIT 2

Got it working thanks to @RC. The only thing I had to change with his answer was to remove the @RequestMapping from the class and have them on the methods only.

  • 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-15T23:44:26+00:00Added an answer on June 15, 2026 at 11:44 pm

    The problem is @RequestParam this annotation tells spring MVC to look for the parameters in the request (ie. form elements with names). Better to use a template here:

    @Controller
    @RequestMapping("/users")
    public class UserController {
    
        @EJB(mappedName="java:global/KSC/UserService!com.ksc.services.UserService")
        private UserService service;
    
        @RequestMapping(value = "")
        public String index(ModelMap model) {
            model.addAttribute("records", service.findAll());
            return "user/index";
        }
    
        @RequestMapping(value = "/create")
        public String create(ModelMap model) {
            model.addAttribute("record", new KCSUser());
            return "user/edit";
        }
    
        @RequestMapping(value = "/edit/{id}")
        public String edit(ModelMap model, @PathVariable("id") int userId) {
            KCSUser user = service.find(userId);
            // Assert.notNull(user, "user was not found");
            model.addAttribute("record", user);
            return "user/edit";
        }
    
        @RequestMapping(value = "/delete/{id}")
        public String delete(ModelMap model, @PathVariable("id") int userId) {
            KCSUser user = service.find(userId);
            // Assert.notNull(user, "user was not found");
            service.remove(user);
    
            return index(model);
        }
    }
    

    Documentation here

    And in main view:

    <a href="${pageContext.request.contextPath}/users/create" class="btn btn-primary">Create</a>
    <!-- ... -->
    <a href="${pageContext.request.contextPath}/users/edit/${row.id}" class="btn">Edit</a>
    <a href="${pageContext.request.contextPath}/users/delete/${row.id}" class="btn btn-danger">Delete</a>
    

    EDIT:

    applicationContext.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd>
    </beans>
    

    Your problem is the mapper you use I think, can you remove <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> and try again?

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

Sidebar

Related Questions

I come from a .NET background and am completely new to Java and am
I come from a Java background and am getting more into .NET, what are
BACKGROUND I am learning Java and currently on JSF. I come from an ASP.NET
I come from a .Net C# background, what's the best way to learn how
I come from a C# background and have to now code in VB.Net (new
I am new to Qt GUI programming and come from a .NET/Winforms background as
I come from a Java background. Please have a look at the code below
I come from an ASP.NET MVC background and am currently going through the following
I come from a .net background so the empty classes (models) that I'm seeing
I come from an ASP .Net background. I am now writing a Java program

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.