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

I am new to ASP.NET MVC3 and trying desperately to just get something simple
I am new to spring MVC. i have below project structure. Below are classes:
I'm new to Spring and AOP in Java (though I've done some related stuff
Im quite new to spring mvc. What I'm trying to achive is separating static
I'm relatively new to .NET and MVC3. I'm having some trouble with the above
I'm trying to get a list of objects to render on a Spring 3
So, for some hours now, I have been trying to do something that I
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'm new to MVC3 and have run into a little problem. I've scoured the

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.