Spring MVC URL not getting resolved correctly -


i created spring project in eclipse. problem that, url not getting resolved in way think should.

web.xml

<servlet>           <servlet-name>mvc-dispatcher</servlet-name>           <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>           <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping>      <servlet-name>mvc-dispatcher</servlet-name>      <url-pattern>/files/*</url-pattern>      <url-pattern>/filestest/*</url-pattern> </servlet-mapping> 

this mvc-dispatcher-servlet.xml

<?xml version="1.0"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:mvc="http://www.springframework.org/schema/mvc"     xmlns:context="http://www.springframework.org/schema/context"     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     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:annotation-driven />      <context:component-scan base-package="com.github.myproject.controllers" />  </beans> 

this controller file:

@controller @requestmapping("/filestest") public class testcontroller {     @requestmapping(value="", method=requestmethod.get)     public @responsebody string getbase() {         system.out.println("base");         return "base";     }      @requestmapping(value="/", method=requestmethod.get)     public @responsebody string getroot() {         system.out.println("root");         return "root";     }      @requestmapping(value="abc", method=requestmethod.get)     public @responsebody string getabc() {         system.out.println("abc");         return "abc";     }      @requestmapping(value = "/abc", method=requestmethod.get)     public @responsebody string getbaseabc() {         system.out.println("base abc");         return "base abc";     }      @requestmapping(value="/{pathvar}", method=requestmethod.get)     public @responsebody string getpathvar(@pathvariable(value="pathvar") string pathvar) {         system.out.println(pathvar);         return pathvar;     } } 

here output got

http://mylocalhost.com/filestest/abc - 404

http://mylocalhost.com/filestest/ - 404

http://mylocalhost.com/filestest - valid output - "base"

from understanding of spring documentation, web.xml should route /filestest requests dispatcherservlet -> routes request controller -> should match correct method.

can please me figure out why getting 404 file not found error urls - http://mylocalhost.com/filestest/abc , http://mylocalhost.com/filestest/ when try deploy , test application?

remove /filestest controller's requestmapping annotation.

spring using mapped path part (*) there no need have servlet prefix inside requestmapping.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -