1

i had created a simple spring-mvc maven project,but when i am trying to run that on server and requesting any page than it is showing me following error:


WARNING: No mapping found for HTTP request with URI [/spring-mvc3/outerlink.html] in DispatcherServlet with name 'spring'

but then i found that my project is not generating controller class in spring-mvc3-target-classes directory

This is my web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>spring-mvc3</display-name>
<welcome-file-list>index.jsp</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>

This is my spring-servlet.xml file:

<?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:tx="http://www.springframework.org/schema/tx" 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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="first"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"></property>
</bean>

</beans>

This is EmpController.java class which is present inside src/main/java first package:

package first;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class EmpController {

@RequestMapping("/outerlink")
public ModelAndView doWork(HttpServletRequest request)
{
    System.out.println("Entered in Model");
    return new ModelAndView("empform");
}
}

This is my Project Structure,my project name is spring-mvc3

enter image description here

Please help me i am badly stuck with this,thanks in advance

yogesh meghnani
  • 729
  • 2
  • 6
  • 11

1 Answers1

1

I think your main problem is you are using html page, if you are using .html page then ModelAndView can't execute. for this you need to make that page as .jsp file.

If you want to use html file as it is then you need to redirect it. As html page is a static page you need to configure in your spring-servlet.xml as below

<mvc:resources mapping="/resources/**" location="/resources/" />

to redrect : return "redirect:resources/htmlPageName"

Spring xml file namespace should have spring mvc.

    <?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:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc" 
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

        <mvc:annotation-driven />
        <context:component-scan base-package="first" />

        <bean 
 class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
            <property name="prefix" value="/WEB-INF/" />
            <property name="suffix" value=".jsp" />
        </bean>

    </beans>

put below jars and java version should java 8

enter image description here

Sangram Badi
  • 4,054
  • 9
  • 45
  • 78
  • thanks..but i tried to use jsp page than also it is showing me same error – yogesh meghnani May 29 '17 at 11:41
  • can you post your project structure – Sangram Badi May 29 '17 at 12:00
  • have you tried to run it as debug ? if no please put a debug point at controller and check whether your request is hitting the controller or not, then please update me – Sangram Badi May 29 '17 at 12:05
  • i checked your namesapce in spring xml file, it seams to be like you are not using spring mvc in your namespace. please check my updated answer – Sangram Badi May 29 '17 at 12:09
  • i had replaced my spring-servlet file's code with yours,but when i run it,it gives me folloeing error:org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from ServletContext resource [/WEB-INF/spring-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 8; The processing instruction target matching "[xX][mM][lL]" is not allowed. – yogesh meghnani May 29 '17 at 13:11
  • also when i requested for link than it agains shows me same Http Status 404 error. Please tell me how to put debug point at controller,i had not done this . – yogesh meghnani May 29 '17 at 13:14
  • i think you have jar problems, you should put all required jars. for debug follow this link https://stackoverflow.com/questions/4733835/how-to-use-breakpoints-in-eclipse. check my updated answers for jars – Sangram Badi May 29 '17 at 14:11
  • I had added all required jars that you listed still getting same error.....but i observed one more thing,i also have another spring mvc project in my eclipse that i had created few days ago which is running successfully but when i am trying to add additional requestmapping for a new request than that it is showing me same error no mapping found when trying to access that new request....hope this will also help you in solving my problem...by the way very thanks for your great effort – yogesh meghnani May 30 '17 at 05:46
  • can you check your java version, make java 8 and try, because i had same problem then i upgrade java to 8 – Sangram Badi May 30 '17 at 06:50
  • Thankyou so much sangram , changing java version works for me,heartly thanks for your effort – yogesh meghnani May 30 '17 at 07:51