0

I have a simple request mapping that opens up an html file residing in static folder. It works correctly when the request mapping is a one part request like '/town' but does not works (returns 404) on urls like '/visual/town'. When I debug, the program falls to the desired place though. It just cannot recognise the file that it points to when the mapping constitutes of two or more parts. This doesn't makes sense to me at all.

This one works :

@Controller("VisualHomeController")
public class HomeController {

    @RequestMapping(value = "/town")
    public String emergentTown() {
        return "static/visual/emergent_town.html";
    }
}

This one does not :

@Controller("VisualHomeController")
public class HomeController {

    @RequestMapping(value = "/visual/town")
    public String emergentTown() {
        return "static/visual/emergent_town.html";
    }
}

And here is my servlet mapping, It seems that the problem arises here :

<servlet-mapping>
    <servlet-name>main</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
4
  • too little info. Commented May 11, 2017 at 13:58
  • I added servlet mapping info Commented May 11, 2017 at 14:01
  • if the control is coming to the correct method, then @RequestMapping is working. No porblem with that. Whatever happens after that is upto your code. how is this a problem with RequestMapping Commented May 11, 2017 at 14:02
  • Because for both request mappings it goes into the correct method, every other things are same but the latter code does not work. The one thing that differs is the url as I pointed out in the question. So there must be something wrong with the servlet mappings or other relating to the background tasks of spring. Commented May 11, 2017 at 14:05

1 Answer 1

1

So, I figured out that the problem is with the servlet mapping.

I needed to add another servlet mapping for the first part of my additional controller which is /visual as :

<servlet-mapping>
    <servlet-name>main</servlet-name>
    <url-pattern>/visual/*</url-pattern>
</servlet-mapping>

Then it worked. So whenever you want to have requests like /.../new_page you need to define the ... as servlet mappings. Note that changing the main servlet mapping to /* is not enough for this purpose.

Note : It still doesn't make sense that why the program falls into the return ... when debugging. I mean, if one more servlet mapping is needed, how front controller can route the request to that method? And while doing so why it can not resolve the view?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.