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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:10:51+00:00 2026-06-15T09:10:51+00:00

I have a spring application and I can’t solve a problem. When I use

  • 0

I have a spring application and I can’t solve a problem. When I use a PathVariable, the value in my RequestMapping is getting added to the URI and the DispatchHandler is getting confused.

For example, when I request /Dashboard/project/1131/

I get HTTP Status 404 - /Dashboard/project/1131/WEB-INF/jsp/projectDetail.jsp

The project/1131 gets added into the path for some reason

When I request /Dashboard/projects Spring finds my .jsp and presents it. /project/{projectId} doesn’t work – I get the behavior described above.

Here’s my controller

@Controller
public class ProjectController {

protected final Log logger = LogFactory.getLog(getClass());

@RequestMapping(value = "projects", method=RequestMethod.GET)
public String projects() {
    return "/projects";
}

@RequestMapping(value="/project/{projectId}", method=RequestMethod.GET)
public String project(@PathVariable("projectId") String projectId, ModelMap map) {
    map.put("projectId", projectId);
    logger.info("Project Id: " + projectId);
    return "/projectDetail";
}

}

My configuration

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"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<!-- Webapp name -->
<display-name>Dashboard</display-name>

<!-- default file name -->
<welcome-file-list>
    <welcome-file>home</welcome-file>
</welcome-file-list>

<!-- spring listener (all spring jars need to be in WEB-INF/lib -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- set servlet to DispatcherService -->
<servlet>
    <servlet-name>dashboard</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- hand all requests to dispatcher service -->
<servlet-mapping>
    <servlet-name>dashboard</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

AppConfig

@Configuration
public class AppConfig {

@Bean
ViewResolver viewResolver() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("WEB-INF/jsp/");
    resolver.setSuffix(".jsp");
    return resolver;
}

}

dashboard-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: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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!-- the packages to scan for annotations -->
<context:component-scan base-package="com.dennisstevens.dashboard.controller" />
<context:component-scan base-package="com.dennisstevens.dashboard" />
<context:component-scan base-package="com.dennisstevens.dashboard.domain" />

<!-- Tell Spring that MVC components are @Annotation Driven -->
<mvc:annotation-driven />

<!-- Tell Spring Dispatch Handler to look in WebContent/resources/ for resources -->
<mvc:resources mapping="/resources/**" location="/resources/" />

<!-- Tell Spring to scan for config annotations -->
<context:annotation-config/>

<!--  TODO: Figure out how to load this in AppConfig -->
<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages" />
</bean>

</beans>

This has to be simple – but I have looked through the documentation and searched the internet for hours. It looks like I am doing everything right from what I can see.

  • 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-15T09:10:55+00:00Added an answer on June 15, 2026 at 9:10 am

    I think having a leading slash in resolver.setPrefix("/WEB-INF/jsp/"); should fix it for you.

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

Sidebar

Related Questions

I have a spring-based web application. In a controller I specified the following: @RequestMapping(value
I have a Spring MVC application trying to use a rich domain model, with
I have a spring web application which a user can deploy on their own
I have a spring MVC application, how can I return a list of users
I have a Spring MVC application where I use hibernate, freemarker. It is setup
I have one spring batch application which can be run from command line. The
I have Spring REST application that can marshall an object to JSON when a
I have a problem with activiti concurrency . We have a wicket spring application
I have Spring MVC web-application. I want to use Hibernate and AJAX. There are
I have a Spring MVC application and a problem with JUnit tests combined with

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.