The requested resource not available in spring mvc - spring

I am trying to learn spring mvc and facing a problem (which seems to be a common one). I have searched a lot of solutions but nothing is helping me out...
My web.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Spring Hello World</display-name>
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>chatbooster</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>chatbooster</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
My chatbooster-servlet.xml is :
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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="com.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
When I try to run hello.jsp, the error is the requested resource is not available.
Hello.jsp:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="i" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Hello World!</h1>
<hr/>
<form action="hi">
Name: <input type="text" name="name"> <input type="submit" value="Submit">
</form>
</body>
</html>
HelloWorldController.ava
#Controller
public class HelloWorldController {
#RequestMapping("/")
public String hello() {
return "hello";
}
#RequestMapping(value = "/hi", method = RequestMethod.GET)
public String hi(#RequestParam("name") String name, Model model) {
String message = "Hi " + name + "!";
model.addAttribute("message", message);
return "hi";
}
}
Edit1:
The problem is occurring because of tomcat server as my simple html page is also not running and it is throwing the same exception. I am using tomcat server version 7. Can anyone hint me out the cause of this exception?

Tomcat doesn't know about hello.jsp since it is inside WEB-INF.
Change
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
to
<welcome-file-list>
<welcome-file>/</welcome-file>
</welcome-file-list>
It will work.

This could be a the case of Hello.jsp. The first letter of Hello.jsp is capitalized yet in your controller you are returning a lower case hello. If you change your controller to return the string "Hello" it should work.

Thank you everyone for your answers. Actually I was able to solve my issue by just changing the location of html and jsp pages from web inf folder to web content folder. I dont know why it worked but pages are being run by the server now.

Related

local server not able to find the welcome.jsp file in sprin web mvc

Project link
I am doing a spring web-mvc app using maven and tomcat server. So the problem is after clicking on the link of the index.jsp, it is not redirecting to welcome.jsp.
controller class
package com.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
public class controller {
#RequestMapping("/welcome")
public String redirect()
{
return "welcome";
} }
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance..."
version="4.0">
<display-name>CrunchifySpringMVCTutorial</display-name>
<servlet>
<servlet-name>crunchify</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>crunchify</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping></web-app>
index.jsp
<!DOCTYPE html >
<html><head><title>Spring MVC Tutorial Series by Crunchify.com</title>
<h3><a href="welcome">Click here to See Welcome Message... /></h3>
</div></body></html>
Welcome.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "ht
<html><head>
<title>Spring MVC Tutorial by Crunchify - Hello World Spring MVC
Example</title></head><body>
Spring MCV Tutorial by Crunchify.
Click <a href="https://crunchify.com/category/java-tutorials/"
target="_blank">here</a> for all Java and <a
href='https://crunchify.com/category/spring-mvc/'
target='_blank'>here</a>
for all Spring MVC, Web Development examples.<br>
</div></body></html>
crunchify-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=..."
<mvc:annotation-driven />
<context:component-scan
base-package="com.controller" />
<mvc:default-servlet-handler />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/JSP/"></property>
<property name="suffix" value=".jsp"></property>
</bean> </beans>
This is my directory structure. i am not getting how to go to welcome.jsp.
Can someone help me?? Why it is not redirecting to the welcome.jsp??
Issue is with your index.jsp
<h3><a href="welcome">Click here to See Welcome Message... /></h3>
You are mentioning direct welcome in anchor which wouldn't work here.
Use is like that
use <form action="page2.jsp">
or
submit to a servlet using
<form action="targetServlet">,
and then:
redirect to page2, using response.sendRedirect("page2.jsp")
or
forward to page2, using request.getRequestDispatcher("page2.jsp").forward()

Spring MVC model is not displaying a string [duplicate]

This question already has answers here:
EL expressions not evaluated in JSP
(5 answers)
Closed 6 years ago.
My project is to let an end user login and then go to another page to display a message. If the login details are wrong it displays an appropriate error message and gives them another chance to login in. The problem is that the message that is meant to be displayed is not. Instead all that is being displayed is;
Message is: ${message}
index.jsp
<form action="login.html" method="post">
Name: <input type="text" name="name"/>
Password: <input type="password" name="password"/>
<input type="submit" value="submit"/>
</form>
LoginController.java
package com.loginmvc.domain;
#Controller
public class LoginController {
#RequestMapping("/login")
public ModelAndView login(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String name = req.getParameter("name");
String password = req.getParameter("password");
if(password.equals("admin")) {
String message = "Welcome " + name;
return new ModelAndView("profilepage", "message", message);
} else {
return new ModelAndView("errorpage", "message",
"Sorry, the name or password is incorrect.");
}
}
}
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<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>*.html</url-pattern>
</servlet-mapping>
</web-app>
spring-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-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="com.loginmvc.domain" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
You are using an old descriptor in your web.xml file. This will result in the EL being ignored:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
If you are following a tutorial, I would recommend that you find a newer one. However, in the meantime, updating your web.xml should solve your immediate problem:
<?xml version="1.0" encoding="UTF-8"?>
<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/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
...
</web-app>
Make sure that you are using : this Taglib in your JSP
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
and to print message : <c:if test="${not empty message}">${message}</c:if>
I highly recommend you to use IDE like eclipse or netbeans so that it would be easy to detect taglib errors and warning in your jsp.

rg.springframework.web.servlet.PageNotFound noHandlerFound.

I've seen this question a lot but however I am still unable to fix my problem. Hope you will be able to guide me.'
I get the following exception when i try to run my super simple spring web app
Mar 24, 2016 9:17:31 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/51SpringWebMaven/] in DispatcherServlet with name 'offers'
Please find my codebase below
OffersController Class
package com.sharat.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class OffersController {
#RequestMapping("/")
public String showHome(){
return "home";
}
}
offers-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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.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-4.2.xsd">
<context:component-scan base-package="com.sharat.web.controller"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsps/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>50SpringBasicWeb</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>offers</display-name>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
home.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Page</title>
</head>
<body>
First JSP Home Page
</body>
</html>
Please guide me to get past this issue. I can't seem to find out what is wrong.
Thanks,
Sharat
It worked without me changing anything after some time. I do not understand why this is unreliable :(
Is there some best practice ?
Thanks,
Sharat

Cant able to run spring application?

I am new to spring i am trying to run the spring application, i am getting the DispatcherServlet class not found exception. The below is the code i used can anyone please help me? I tried many solution provided in stackoverflow and google but i didn't get answer for this problem. Thanks in advance.
package com.raistudies.actions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class HelloWorldAction {
#RequestMapping(value = "/hello", method = RequestMethod.GET)
public ModelAndView sayHello(Model model) {
System.out.println(" hellow world ");
ModelAndView mav = new ModelAndView();
mav.setViewName("hello");
model.addAttribute("helloMessage",
"Hello World from my spring 3 mvc application");
return mav;
}
}
hello.jsp - WEB-INF/jsp/
<html>
<head>
<title>Hello world with spring 3 mvc </title>
</head>
<body>
<h1>Welcome! Spring MVC is working well.</h1><br />
${helloMessage}
</body>
</html>
index.jsp - WEB-INF
<html>
<head>
<title>rai studies</title>
</head>
<body>
Welcome...
<br>Click here to check the output :-)
</body>
</html>
app-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:component-scan base-package="com.raistudies.actions" />
<context:annotation-config />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>HWEWS3MVCIE</display-name>
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springfrmaework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/app-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
My dependencies:
commons-logging-1.1.2.jar
jstl-1.2.jar
log4j-1.2.16.jar
spring-aspects-3.2.5.RELEASE.jar
spring-beans-3.2.5.RELEASE.jar
spring-context-3.2.5.RELEASE.jar
spring-core-3.2.5.RELEASE.jar
spring-expression-3.2.5.RELEASE.jar
spring-web-3.2.5.RELEASE.jar
spring-webmvc-3.2.5.RELEASE.jar
<servlet-class>org.springfrmaework.web.servlet.DispatcherServlet</servlet-class>
In above line there is spelling mistake. It should be
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

Why doesn't bean name of /home.jsp not work for BeanNameUrlHandlerMapping?

In the following program, if I replace "/home.htm" with "/home.jsp" in dispatcher-servlet.xml and index.jsp, then the server is not able to find home.jsp. Are strings ending with ".jsp" invalid as bean name?
dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
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/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<bean id="handlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<bean name="/home.htm" class="com.sample.HomePageController" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
index.jsp
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Dynamic Tiles</title>
</head>
<body>
<form action="/home.htm" method="post">
Please enter your name:
<input type="text" name="visitorName" />
<input type="submit" value="Go"/>
</form>
</body>
</html>
HomePageController.java
package com.sample;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
public class HomePageController extends AbstractController {
private static Logger logger = Logger.getLogger(HomePageController.class);
HomePageController () {
logger.info("Constructing HomePageController object");
};
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.info("Handling request for home.jsp");
return new ModelAndView("home", "visitorName", request.getParameter("visitorName"));
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>*.htm</url-pattern>
</servlet-mapping>
</web-app>
There are several pieces of your application that need to be modified for it to work as intended. The first piece is the Dispatcher Servlet mapping in web.xml. In Spring the dispatcher is used to route particular requests from the client to Spring controllers within the application. What requests are routed via the dispatcher is determined by the url-pattern specified in the web.xml file for the servlet: org.springframework.web.servlet.DispatcherServlet.
In your case we want to set the url-pattern to something that does not conflict with accessing your jsp files. Since you have specified a viewResolver in your Spring configuration that prefixes generic names with /WEB-INF/jsp/ and suffixes them with .jsp, we must use a url-pattern other than .jsp.
If the .jsp url-pattern were used, a request would first be processed by the dispatcher servlet and routed to any mapped controller. If the controller attempts to use a view name to navigate to another page, for example, home, the view name is prefixed/suffixed resulting in a url: /WEB-INF/jsp/home.jsp. This constructed URL matches the .jsp url-pattern specified for the dispatcher and an attempt to route /WEB-INF/jsp/home.jsp is made, most likely failing because no mapping is found.
To remedy this problem we setup your web.xml as follows:
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
</web-app>
As you can see, we map the dispatcher to the url-pattern *.do. This allows the dispatcher to be used to route requests without interference with common file prefixes.
Changing the url-pattern to *.do requires us to change the action on your form. I modified your form to the following:
Index.jsp
<%# page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
<title>Dynamic Tiles</title>
</head>
<body>
<form action="home.do" method="post">
Please enter your name: <input type="text" name="visitorName" />
<input type="submit" value="Go" />
</form>
</body>
</html>
I also assumed that all of your .jsp files are located within the WEB-INF directory. This requires us to use a controller to access each of these .jsp files. Mappings to the controllers must be created in your Spring configuration file for the dispatcher and the appropriate controller for index.jsp must be created. Notice that I am using the .do suffix for the mappings.
dispatcher-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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="handlerMapping"
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<bean name="/home.do" class="com.sample.HomePageController" />
<bean name="/index.do" class="com.sample.IndexPageController" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
IndexPageController.java
package com.sample;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
public class IndexPageController extends AbstractController {
#Override
protected ModelAndView handleRequestInternal(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
return new ModelAndView("index");
}
}
Just to be thorough, I created a home.jsp file to test the application since one was not provided. Here is my home.jsp file:
Home.jsp
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
Hello, ${visitorName}
</h1>
<P> The time on the server is ${serverTime}. </P>
</body>
</html>
You decided that dispatcher would only handle .htm-ended urls but then you want it to handle .jsp-ended url. For the latter to work just change url-pattern element's content in web.xml to, for example, something like this:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>

Resources