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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:15:46+00:00 2026-05-26T12:15:46+00:00

I am new in spring mvc3,and I am trying to create a simple project

  • 0

I am new in spring mvc3,and I am trying to create a simple project to get close to spring mvc3.

Now I meet some problem when I try to server some static resources files.

Because I use the url-pattern (/) in the web.xml:

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

So,when I enter: http://locaohost:8080/spring/res/css/main.css. I will get the 404 error.

From the spring document,I try to use the <mvc:resource location="/res/" mapping="/res/**" />

But if I add this tag in the spring-servlet.xml,I found that,I can get the resources file now,but I can not access other page.

That’s to say,I have a controller:

@Controller
@RequestMapping("/example")
public class HelloController {

    @RequestMapping("hello")
    public String hello(Model model){
        model.addAttribute("name", "John");
        return "spring.example.hello";
    }
}

When I visit: http://locaohost:8080/spring/example/hello,I will get 404 now.

But If I remove the tag: <mvc:resource xxx/>

I can access http://locaohost:8080/spring/example/hello,but I can not get the .css/.js file.

Through debugger in eclipse,I found that when spring init the handerMapping in the method “initHanderMapping” of “DispatchServlet”,it created two mapping instance:
BeanNameUrlHandlerMapping and SimpleUrlHandlerMapping.

The handelrMap property of the BeanNameUrlHandlerMapping is always empty while the SimpleUrlHandlerMapping always contain the url-matching mappings.

When I add the tag ,its handerMapping property is: {/res/**=org.springframework.web.servlet.resource.ResourceHttpRequestHandler@1120eed}

When I remove the tag,the handelrMapping is :{/example/hello=com.spring.controller.HelloController@1b5438d, /example/hello.*=com.spring.controller.HelloController@1b5438d, /example/hello/=com.spring.controller.HelloController@1b5438d}.

It seems that ,the {/res/**=xxxx} override other mappings {/example/helloxxxxx}

This is the spring-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/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">

<!--    <mvc:resources location="/res/" mapping="/res/**"></mvc:resources>-->
    <context:component-scan base-package="com.spring.controller" />
    <bean id="viewResolver" class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
    </bean>
    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/jsp/tile_def.xml</value>
            </list>
        </property>
    </bean>
</beans>

How to fix it?

  • 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-05-26T12:15:47+00:00Added an answer on May 26, 2026 at 12:15 pm

    Try adding <mvc:annotation-driven /> to your context.

    <mvc:resource...> overrides the default behavior of spring mvc. If you add <mvc:annotation-driven /> to your spring-servlet.xml, it should forcibly register all required handlers.

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

Sidebar

Related Questions

Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring
I'm trying to create a multi-level editor in MVC3. By multi-level I mean that
I am trying to render a ViewModel using Razor and MVC3. For some reason
I'm trying to implement ServiceStack into my MVC3 project, and am following the tutorial
I am trying to send some JSON data to my ASP.NET MVC3 controller action
I'm trying to implement RedirectAttributes feature in Spring MVC 3.1-Release I'm sending simple form
I'm new to asp.net, mvc3 and entity framework. I'm trying to develop a mvc3
I'm trying to get my MVC3 application to use MySql database instead of Sql
I am trying to create a simple application using SpringMVC for learning purpose. I
I'm relatively new to .NET and MVC3. I'm having some trouble with the above

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.