0

I am trying to build a SpringMVC application and try to invoke a controller. it is giving me an error of java.io.FileNotFound Exception. Application is built with a RootContext value 'springmvc' and installed on Websphere 9

URL being invoked to hit controller -

http://localhost:9080/springmvc/logon

and this URL is giving a filenotFound for ' /logon.' But, at the same time http://localhost:9080/springmvc/ gets tied with Controller and giving the output as 'Hello World'. I am not sure on why /logon is not being recognized.

I have tried by keeping URL Pattern in web.xml as /springmvc/ or /springmvc/* but they all are not working. I have tried giving complete path in Controllers too.

Controller '''

 ` @Controller
public class AdminController{

@RequestMapping(value="/logon" , method = RequestMethod.GET)
@ResponseBody
public String config(){
system.out.println("Inside Config Method");
return "Hello World!";
} ` 

'''

Web.xml

`

<servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/todo-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/springmvc/*</url-pattern>
</servlet-mapping> ` 

todo-servlet.xml -

` <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="springmvc.com.controller" />

    <mvc:annotation-driven />

</beans>` 

I expect http://localhost:9080/springmvc/logon to return the response from AdminController class. Kindly suggest what am i missing or what url-pattern shouuld i try?

1 Answers1

0

Assuming that AdminController is on the springmvc.com.controller package. The problem I see is the url-pattern, In this case the logon is expected on the path: http://localhost:9080/springmvc/springmvc/logon

The first one (springmvc) is the context of the application, all points start on it. The second is inside your application.

You need to define / to get the expected result.

David SK
  • 814
  • 7
  • 21
  • I tried by changing URL Pattern in web.xml to '/' . Initally it was giving me an error and application was not being deplyed. Used this (https://stackoverflow.com/questions/41773355/webapp-srve0278e-error-while-adding-servlet-mapping) suggestion for deploying the app . But with this change also app is not working and http://localhost:9080/springmvc/logon is giving FilenotFound exception. – Rikky Saxena May 17 '19 at 22:17
  • Remove / from servlet mapping url-pattern after /springmvc/* you can use this /springmvc* – MangduYogii Jun 07 '19 at 07:24
  • It worked as David said. After fixing URL pattern i had some issues with my Maven configuration too.I downloaded the war file which was being deployed and figured out that changes were not being reflected. After clean builds and refreshing the project this all worked. – Rikky Saxena Jun 10 '19 at 18:46