1

I'm struggling with errors on the web.xml where all the pages are comming up as 404, possibly there is a root path but I can not be sure where its set etc..

This is my current 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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Spring3MVC</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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> </web-app> 

My listener controller is like this

/* * User */ @RequestMapping(value={"/user/{id}"}, method=RequestMethod.GET) public ModelAndView profileDisplay( HttpServletRequest request, HttpServletResponse response, @RequestParam(value="id", required=false) String id ) throws UnknownHostException, MongoException { ServiceSerlvet.appendSesssion(request); //get search ALL users BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("_id", new ObjectId(id)); List<DBObject> searchResponse = PersonController.searchUsers(searchQuery); //System.out.println("response from search user method: "+searchResponse); return new ModelAndView("user", "people", searchResponse); } 

This is the current error that is coming out. How come its not mapping, how do I go about fixing this?

INFO: Server startup in 5904 ms 01-Nov-2012 19:40:21 org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping found for HTTP request with URI [/springApp21] in DispatcherServlet with name 'spring' 01-Nov-2012 19:40:22 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleNoSuchRequestHandlingMethod WARNING: No matching handler method found for servlet request: path '/user', method 'GET', parameters map['id' -> array<String>['4fa6eddc0234964172522248']] 01-Nov-2012 19:40:24 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleNoSuchRequestHandlingMethod WARNING: No matching handler method found for servlet request: path '/user', method 'GET', parameters map['id' -> array<String>['4fa6eddc0234964172522248']] 
5
  • 1
    What is the url you type on web browser Commented Nov 1, 2012 at 20:21
  • When I run from a Eclipse as "My Eclipse Application" it opens the page too robot-oi772f3re:8080/springApp21 Commented Nov 1, 2012 at 21:30
  • are you getting home page or it 404 Commented Nov 1, 2012 at 21:36
  • Yeah its a 404, it seems to only want to work for the home page if I change <url-pattern>/*</url-pattern> to <url-pattern>springApp21/*</url-pattern> but I am sure that can't be right and it then only takes me to the home page - my other granualar mappings are not working Commented Nov 1, 2012 at 22:18
  • Is there a property parameter I'm missing? I'd like to have just one url-pattern element in the web.xml and granulalr mapping handled in the controllers. - I will need to add exceptions to ensure image, js and css paths don't get handled by the controller too. They start with security tags of some sorts also listed in the web.xml. I'm very new to Java spring - not sure how to set it up properly for this kind of scalability. Commented Nov 1, 2012 at 23:05

2 Answers 2

2

I answered one of your questions prior off the top of my head. I have now have access to one of my spring apps. Here is a better configuration.

Notice the change to the web.xml, I apologize but mapping to /* causes all of your requests to be resolved by the dispatcher. In a sense your creating a loop, your initial mapping will be forwarded by the dispatcher to the controller which will then use a view resolver to map where your request should be forwarded. Mapping to /* causes the view resolver mapping to be handled by the dispatcher.

Changing to / causes all unmapped urls to be handled by the dispatcher, so your initial mapping is handled by the dispatcher, which sends it to the controller and the mapping created by your viewresolver will be mapped to the .jsp causing it to not be picked up by the dispatcher. My apologies.

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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Spring3MVC</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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> </web-app> 

spring-config.xml (You must change the component scan)

<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> <!-- Enables the Spring MVC @Controller programming model --> <annotation-driven/> <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> <resources location="/resources/" mapping="/resources/**"/> <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/views/"/> <beans:property name="suffix" value=".jsp"/> </beans:bean> <context:component-scan base-package="package.with.controllers" /> </beans:beans> 

Controller

@RequestMapping(value={"/user/{id}"}, method=RequestMethod.GET) public ModelAndView profileDisplay( HttpServletRequest request, HttpServletResponse response, @RequestParam(value="id", required=false) String id ) throws UnknownHostException, MongoException { ServiceSerlvet.appendSesssion(request); //get search ALL users BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("_id", new ObjectId(id)); List<DBObject> searchResponse = PersonController.searchUsers(searchQuery); //System.out.println("response from search user method: "+searchResponse); //This should display "WEB-INF/views/user.jsp" you may need to adjust. return new ModelAndView("user", "people", searchResponse); } 
Sign up to request clarification or add additional context in comments.

1 Comment

I helped him on a previous question and accidentally misinformed him of how to map the dispatcher servlet. {id} is the syntax used to denote a uri template. Essentially the id parameter will be pulled from the url of the request, I believe this is referred to as restful url.
0

Thank you Kbm for coming back to me. I've altered my web.xml and the general mappings have resolved. I've ran into the problem you mentioned with the css,js,image files also getting passed.

I've tried to add intercept url's but something is not working still. http is highlighted red in the web.xml. When I hover over it in eclipse it expresses

cvc-complex-type.2.4.a: Invalid content was found starting with element 'http'. One of '{"http:// java.sun.com/xml/ns/javaee":description, "http://java.sun.com/xml/ns/javaee":display-name, "http:// java.sun.com/xml/ns/javaee":icon, "http://java.sun.com/xml/ns/javaee":distributable, "http:// java.sun.com/xml/ns/javaee":context-param, "http://java.sun.com/xml/ns/javaee":filter, "http:// java.sun.com/xml/ns/javaee":filter-mapping, "http://java.sun.com/xml/ns/javaee":listener, "http:// java.sun.com/xml/ns/javaee":servlet, "http://java.sun.com/xml/ns/javaee":servlet-mapping, "http:// java.sun.com/xml/ns/javaee":session-config, "http://java.sun.com/xml/ns/javaee":mime-mapping, "http://java.sun.com/xml/ns/javaee":welcome-file-list, "http://java.sun.com/xml/ns/javaee":error- page, "http://java.sun.com/xml/ns/javaee":jsp-config, "http://java.sun.com/xml/ns/javaee":security- constraint, "http://java.sun.com/xml/ns/javaee":login-config, "http://java.sun.com/xml/ns/ javaee":security-role, "http://java.sun.com/xml/ns/javaee":env-entry, "http://java.sun.com/xml/ns/ javaee":ejb-ref, "http://java.sun.com/xml/ns/javaee":ejb-local-ref, "http://java.sun.com/xml/ns/ javaee":service-ref, "http://java.sun.com/xml/ns/javaee":resource-ref, "http://java.sun.com/xml/ns/ javaee":resource-env-ref, "http://java.sun.com/xml/ns/javaee":message-destination-ref, "http:// java.sun.com/xml/ns/javaee":persistence-context-ref, "http://java.sun.com/xml/ns/ javaee":persistence-unit-ref, "http://java.sun.com/xml/ns/javaee":post-construct, "http:// java.sun.com/xml/ns/javaee":pre-destroy, "http://java.sun.com/xml/ns/javaee":message- destination, "http://java.sun.com/xml/ns/javaee":locale-encoding-mapping-list}' is expected.

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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Spring3MVC</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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> <http auto-config='true'> <intercept-url pattern="/css/**" filters="none" /> <intercept-url pattern="/images/**" filters="none" /> <intercept-url pattern="/js/**" filters="none" /> </http> </web-app> 

3 Comments

Please post as new question or modify your question...do not ask the question in the same thread as people see the page which is unanswered..
Hello Pratap, I would love to ask a new question, but my accounts been banned from asking new questions. I can only seem to comment or add another answer. I would love to resolve this pattern issue - but for now I have to skip over this and continue trying to learn and fulfil other parts of the project
Hello @divine no - not picked this up since