0

Yep, I know - there are tones of such questions. I tryed to scan all of them, but the didn't help me. Here is my code:

dispatcher servlet

<context:component-scan base-package="com.package.controller" />
<mvc:annotation-driven />
<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" />

web.xml

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

Controller:

@Controller
public class HomeController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public ModelAndView hello() {
    return new ModelAndView("index");
   }
}

Files location

HomeController is located in com.package.controller package.

index.jsp is located in WEB-INF/jsp/ package.

URL I'm trying to access is: localhost:8080/hello.do

What am I doing wrong? Thanks for help!

2 Answers2

0

I have run your project the code is working fine, Can you follow the below project structure?

enter image description here

MDaniyal
  • 1,097
  • 3
  • 13
  • 29
0

Your url is not correct. Try with localhost:8080/"yourapplicationName"/hello.do. For example in my case if my application war file is abc.war then the url would be localhost:8080/abc/hello.do

KayV
  • 12,987
  • 11
  • 98
  • 148
  • No, the code is working fine issue is might be with project structure. with this URL `http://localhost:9090/hello.do` – MDaniyal Apr 08 '16 at 05:21