1

I know same question has asked before but its not helping me i am trying to solve this for last 2 days i am using "spring-framework-4.2.4.RELEASE" this is my code : web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0"metadata-complete="true">
<display-name>Spring MVC Application</display-name>
<servlet>
  <servlet-name>HelloWeb</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
   <servlet-name>HelloWeb</servlet-name>
   <url-pattern>*.jsp</url-pattern>
</servlet-mapping>
</web-app>

HelloWeb-servlet.xml:

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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">

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

</beans>

HelloController.java

package com.tutorialspoint.controller;


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

@Controller
public class HelloController {

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String printHello(ModelMap model) {
        model.addAttribute("message", "Hello Spring MVC Framework!");

       return "hello";
    }
 }

This is my hello.jsp. and the path of this jsp is WEB-INF/jsp/hello.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
  <h2>${message}</h2>
</body>
</html>
Betlista
  • 10,327
  • 13
  • 69
  • 110
Kunal Batra
  • 821
  • 3
  • 14
  • 35
  • I checked that link already their issue resolved by adding this contextConfigLocation /WEB-INF/HelloWeb-servlet.xml org.springframework.web.context.ContextLoaderListener in web.xml i tried the same but its still showing the same error – Kunal Batra Jan 31 '16 at 19:38
  • 1
    you didn't read properly : check the top answer – Jérémie B Jan 31 '16 at 19:40
  • http://localhost:8080/HelloWeb/hello 404 status nnot found – Kunal Batra Jan 31 '16 at 19:47
  • Add .jsp in the end of your URL. It's required by servlet mapping. – eg04lt3r Jan 31 '16 at 19:49
  • And sir one more thing i made a one more jsp with name NewFile.jsp in WebContent not in web-inf/jsp when i tried to run the jsp i got the warning WARNING: No mapping found for HTTP request with URI [/HelloWeb/NewFile.jsp] in DispatcherServlet with name 'HelloWeb' i am simlply accessing the jsp it should print hello world – Kunal Batra Jan 31 '16 at 19:51
  • on hitting this jsp http://localhost:8080/HelloWeb/hello.jsp am getting WARNING: No mapping found for HTTP request with URI [/HelloWeb/hello.jsp] in DispatcherServlet with name 'HelloWeb' – Kunal Batra Jan 31 '16 at 19:52
  • "HelloWeb" is not part of your servlet mapping's URL pattern. Try http://localhost:8080/hello.jsp – Frans Jan 31 '16 at 20:13
  • Where is your controller configured to be used in Spring? You have no scanning, nor the bean in XML... – Betlista Jan 31 '16 at 20:34

1 Answers1

0

Try doing the following:

  1. Add <context:component-scan base-package="com.tutorialspoint.controller"/> to your HelloWeb-Servlet.xml.
  2. change <url-pattern>*.jsp</url-pattern> to <url-pattern>/web/*</url-pattern>

Then hopefully you will be able to access localhost:8080/web/hello.

Mustafa
  • 5,624
  • 3
  • 24
  • 40