1

I am having issue in spring3 frameowrk.org.springframework.web.servlet.DispatcherServlet

file name is WelcomeController.java

package com.rethink.controller;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/welcome")
public class WelcomeController {

    @RequestMapping(method = RequestMethod.GET)
    public String displayMessage(Map<String, String> map){
            System.out.println("In");
        map.put("loginmessage","Please Login with Your Details");       
        return "index";
    }

}

this is my web.xml and motion-comics-servlet.xml

Click here for web.xml and motion-comics-servlet.xml screen shot

I have placed my view in Web Pages/Web-INF/jsp/index.jsp

no matter what i try i just can't make it to work....

my help and advise will be much appreciated ....

thanks in advance

Ahmed
  • 13
  • 5
  • try /** (slashStarStar) in url pattern in web.xml in servlet mapping – no one May 16 '16 at 12:17
  • @lamba sorry this doesn't worked either – Ahmed May 16 '16 at 13:50
  • @Ahmed Do you wanna say that you have kept your index.jsp file under the location - WebContent/Web-INF/jsp/index.jsp ? – asg May 16 '16 at 14:04
  • So two things to look at : 1. are you getting control in the controller class if you debug your application? 2. If yes, then whether your views location is correct? Please let me know your findings. – asg May 16 '16 at 14:08
  • @asg, first of all thanks for your reply ...... yes i totally missed it to check weather or not the controller gets a hit or not ..... and upon debugging i found that the controller doesn't gets hit. – Ahmed May 17 '16 at 06:39
  • another thing the console sends this message as well : Warning: No mapping found for HTTP request with URI [/motion-comics/welcome] in DispatcherServlet with name 'motion-comics' – Ahmed May 17 '16 at 06:41
  • Try adding request mapping on your method and see if that is accessible. @RequestMapping(method = RequestMethod.GET, value = "/abc"). After adding this, try accessing method with URI - [/motion-comics/welcome/abc] – asg May 17 '16 at 06:55
  • _Warning: No mapping found for HTTP request with URI [/motion-comics/welcome/abc] in DispatcherServlet_ with name 'motion-comics' [XML link](http://i.stack.imgur.com/bBVoh.gif) **also please check my web.xml and servlet.xml as well** – Ahmed May 17 '16 at 07:56
  • @Ahmed, I have added answer. Please check if that solves your problem. – asg May 19 '16 at 09:37

2 Answers2

0

You can verify the spring web mvc logs, whether the controller is getting registered for that URL or not. Also verify whether the component scan is properly set or not.

Further you can verify the view resolver is configured appropriately or not.

For more detailed understanding check this post

Community
  • 1
  • 1
Chaitu
  • 61
  • 5
  • thanks for the input man but even after adding this does not work.... but what about how can i add this?? any help wold be much appriciated – Ahmed May 16 '16 at 13:51
  • You need to add it in applicationContext.xml. Please refer to spring docs at http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-config – Chaitu May 16 '16 at 14:05
  • .. added but started receiving this error : The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'. – Ahmed May 17 '16 at 06:42
0

I tried some examples and found out couple of configuration changes are required in your code.

  1. Add < mvc:annotation-driven /> to your motion-comics-servlet.xml file.
<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:context="http://www.springframework.org/schema/context"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xsi:schemaLocation="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.xsd
                         http://www.springframework.org/schema/mvc 
                         http://www.springframework.org/schema/mvc/spring-mvc.xsd">

      <!-- Add this to your xml file -->
      <mvc:annotation-driven/>

      <!-- Make sure that you are scanning all your packages required for your application -->
      <context:component-scan base-package="com.rethink.controller"></context:component-scan>       


      <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"

              <property name="prefix">
                  <value>/WEB-INF/jsp/</value>
               </property>
              <property name="suffix">
                 <value>.jsp</value>
              </property>
        </bean>

</beans>
  1. Change motion-comics servlet-mapping to the following configuration. Change '/*' to '/'. Remove *.

     <servlet-mapping>
        <servlet-name>motion-comcis</servlet-name>
        <url-pattern>/</url-pattern>
     </servlet-mapping>
    

Please let me know if you run into any issues.

asg
  • 2,248
  • 3
  • 18
  • 26