1

BE GENEROUS AND TELL US WHY I AM HAVING THIS SILLY ISSUE

Everything works fine with no mapping! but I have a simple issue. I have set a parent mapping @ "/hello" and sub-mapped a method @ "/showForm", Dispatcher is set to "/" but I get 404 (see code fig. 3). I couldn't find an answer to an issue SIMILAR to mine.

See code below & TAGS for my setup

Controller fig.1

   @Controller
    @RequestMapping("/hello")
    public class HelloWorldController {



        @RequestMapping("/showForm")
        public String showForm() {
            return "hello-world";
        }

web.xml fig.2

<servlet>
    <servlet-name>yktech</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>yktech</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Tomcat Error fig.3

Type Status Report

Message /yktech/hello/WEB-INF/view/hello-world.jsp

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

EDIT: FORGOT THE BEAN FIG. 4

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

EDIT: STRUCTURE TREE ( MESSY I KNOW )

enter image description here

edit 4 , index.jsp

<html>
<body>
<h2>Welcome to my homepage
</h2>
<a href="hello/showForm">Show form</a>

<a href="Student/showForm">Show STUDENT form</a>
</body>
</html>

edit 5 pom.xml

<project
 xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.yktech</groupId>
  <artifactId>yktech</artifactId>
  <packaging>war</packaging>
  <version>1.0</version>
  <name>yktech</name>
  <url>http://maven.apache.org</url>


  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.3.17.RELEASE</version>
</dependency>

 <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
     </dependency>    
  </dependencies>
  <build>
    <finalName>yktech</finalName>
  </build>
</project>

EDIT 6 , SERVER LOG , MAPPING URLS

INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/yktech-servlet.xml]
Jul 30, 2018 10:19:30 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello/processForm] onto handler 'helloWorldController'
Jul 30, 2018 10:19:30 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello/processForm.*] onto handler 'helloWorldController'
Jul 30, 2018 10:19:30 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello/processForm/] onto handler 'helloWorldController'
Jul 30, 2018 10:19:30 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello/processFormVersionTwo] onto handler 'helloWorldController'
Jul 30, 2018 10:19:30 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello/processFormVersionTwo.*] onto handler 'helloWorldController'
Jul 30, 2018 10:19:30 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello/processFormVersionTwo/] onto handler 'helloWorldController'
Jul 30, 2018 10:19:30 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello/showForm] onto handler 'helloWorldController'
Jul 30, 2018 10:19:30 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello/showForm.*] onto handler 'helloWorldController'
Jul 30, 2018 10:19:30 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping 

registerHandler
    INFO: Mapped URL path [/hello/showForm/] onto handler 'helloWorldController'

... CARRIES ON SHOWS NO ERRORS....
Alessio
  • 3,404
  • 19
  • 35
  • 48
Kyan
  • 475
  • 5
  • 20
  • Check this out https://stackoverflow.com/questions/43186315/tomcat-404-error-the-origin-server-did-not-find-a-current-representation-for-th/43186803 – AchillesVan Jul 30 '18 at 20:08
  • I added structure tree at the bottom, have a look. Did look at that earlier, didn't solve my issue. It works all fine - i can access idnex.jsp, its just the mapped links on index don't work. I'll edit index in in a second – Kyan Jul 30 '18 at 20:10
  • Post your pom.xml as well – AchillesVan Jul 30 '18 at 20:43
  • posted, see edit. --- my main concern is - index.jsp works as expected so does showForm but as soon as I map the class to set it as a parent it all goes pear shaped – Kyan Jul 30 '18 at 20:46
  • Georges, I am looking at error /yktech/hello/WEB-INF/view/hello-world.jsp shouldn't it be /yktech/web-inf/view/hello/hello-world.jsp ? – Kyan Jul 30 '18 at 20:51
  • Try changing your servlet name to `dispatcher-servlet` – Nishan Dhungana Jul 31 '18 at 04:47
  • You mean in web.xml and then change the name of yktech.xml ? The dispatcher works fine , it points to index.jsp but doesn't map properly. could this still be the issue? – Kyan Jul 31 '18 at 04:54

2 Answers2

0

Try this: Requests to /hello will be handled by whatever() while request to /hello/showForm will be handled by showForm()

@Controller
    @RequestMapping("/hello")
    public class HelloWorldController {

@RequestMapping("/")
        public String whatever() {
            return "whatever";
        }

        @RequestMapping("/showForm")
        public String showForm() {
            return "hello-world";
        }
AchillesVan
  • 4,156
  • 3
  • 35
  • 47
  • Nothing, again. Completely lost here.... Type Status Report Message /yktech/hello/WEB-INF/view/helloworld.jsp Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists – Kyan Jul 31 '18 at 04:46
0

Issue is in the view resolver bean, the prefix does not have a "/" in the beginning causing Spring to call any parented mapping requests from root rather than from /WEB-INF/view

Kyan
  • 475
  • 5
  • 20