In my project using Spring MVC and JSON, I configure my web.xml file following as:
Web.xml
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
My Controller:
#Controller
public class HomeController {
#RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
return "home";
}
#RequestMapping(value = "/json", method = RequestMethod.GET, produces = "application/json")
public #ResponseBody List<Person> personsReturn(#RequestParam("name") String name, #RequestParam("age") int age) {
Person p1 = new Person("dat1", 11);
Person p2 = new Person("dat2", 22);
Person p3 = new Person("dat3", 33);
Person p4 = new Person("dat4", 44);
List<Person> lists = new ArrayList<Person>();
if (name.equals("dat")) {
lists.add(p1);
lists.add(p2);
} else {
lists.add(p3);
lists.add(p4);
}
return lists;
}
}
My Servlet-Context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.luongkhanh.restfulspringmvc" />
</beans:beans>
I can get data from JSON by URL:
http://localhost:9999/restfulspringmvc/json?name=dat1&age=11
Result JSON:
[{"name":"dat3","age":33},{"name":"dat4","age":44}]
But If I want to get the image by URL at location, it's unsuccessful:
http://localhost:9999/restfulspringmvc/images/avatar.jpg
Logger in eclipse alert an exception:
ARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/restfulspringmvc/images/avatar.jpg] in DispatcherServlet with name 'appServlet'
How to configure to get image from URL by Browser? Thank you so much !!
You have configured your DispatcherServlet to use the url-pattern / This overrides the default servlet mapping of the container.
The default servlet mapping is used to load any resources or requests without an explicit mapping in web.xml. Typically static resources are loaded using this. If you override it by specifying it as a pattern for your servlet in web.xml then you have to take care of loading the resources yourself
Spring MVC helps by providing resource handling via
You have to specify the mapping which matches your static resources url pattern and the location where your resources reside physically
You did specify
<resources mapping="/resources/**" location="/resources/" />
but your image does not reside in a resources folder under webapp Maven folder. Instead its in images folder. Hence you have to add another resources tag like this
<resources mapping="/images/**" location="/images/" />
NB The mapping attribute and the location attribute does not have to correspond. For example you can have a url like
http://localhost:9999/restfulspringmvc/images/avatar.jpg
and your images are in /static-resources/images under webapp the your mapping will be
<resources mapping="/images/**" location="/static-resources/images/" />
You can also have multiple resources specification in the same application context
Related
I am trying to load my Spring application and I have only html files to render but it is not able show any html file. It is always showing 404 error. But when I am trying to run it directly html file using tomcat then it will able to show my html files.
Below is my directory structure
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">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>ankServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ankServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<context:annotation-config />
<!-- Resolves views selected for rendering by #Controllers to .htmlresources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/resources/html/" />
<beans:property name="suffix" value=".html" />
</beans:bean>
<context:component-scan base-package="com.ankit" />
</beans:beans>
HomeController.java
#Controller
public class HomeController {
#RequestMapping(value = "/login", method = RequestMethod.GET)
public String displayLogin(HttpServletRequest request, HttpServletResponse response)
{
return "login";
}
Try to change this:
<servlet-mapping>
<servlet-name>ankServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
To:
<servlet-mapping>
<servlet-name>ankServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I cannot access files in resource directory. What is the problem?
in servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.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.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.example.test" />
</beans:beans>
in 'HomeController.java'
#RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
File file = new File("/resources/sample/text.txt");
if (file.exists()) {
logger.info("file found.");
} else {
logger.info("file not found.");
}
return "home";
}
in web.xml (default)
<?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">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Oups, that is not the correct way to access resources in a web application.
First, your resource paths are relative to the ServetContext path, so you should not try to use them as file system absolute paths. But in addition, you cannot be sure that they exist as true files.
The servlet specifications allow a servlet container not to explode a war file, prodided it is able to correctly serve resources through ServletContext.getResourceAsStream(java.lang.String path)
That means that you should only use resources as read-only through ServletContext.getResourceAsStream(java.lang.String path) and never try to use them as true files.
hi i'm trying to change my default home page for another one but i couldn't do it, so i try to redirect the page from the default home page to the one i want, but i get this error
No mapping found for HTTP request with URI:
[/myapp/WEB-INF/views/index.html] in DispatcherServlet with name
'appServlet'
this is my setup i left everything by default when i create the project with spring tools suite
this is my servlet-contex.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value="" />
</beans:bean>
<context:component-scan base-package="com.proj.myapp" />
this is my 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">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
this is my deafult home file
home.jsp
enter code here
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
Hello world!
<c:redirect url="/indice.html"/>
</h1>
</body>
</html>
and this is the page i want to be redirected
enter code here
<html>
<body>
<h1>
INDICE
</h1>
</body>
</html>
and my contoller
#Controller
public class HomeController {
#RequestMapping(value = "/")
public String home() {
return "home.jsp";
}
#RequestMapping(value = "/indice.html")
public String indice() {
return "indice.html";
}
}
and i get this error
No mapping found for HTTP request with URI:
[/myapp/WEB-INF/views/indice.html] in DispatcherServlet with name
'appServlet'
As from your code suffix property value is blank so you need to pass the type of suffix to this property in in servlet-context.xml.
You have to change it
<beans:property name="suffix" value=".jsp" />
and your indices.html to indices.jsp then it will work.
But if you want to work it with html file but .html files are static and do not require processing by a servlet then it is more efficient, and simpler, to use an mapping. This requires Spring 3.0.4+.
For example:
<mvc:resources mapping="/static/**" location="/static/" />
which would pass through all requests starting with /static/ to the webapp/static/ directory.
So by putting indices.html in webapp/static/ and using return "indices.html"; from your method, Spring should find the view.
I am trying to set up a webapp that get the body of a POST request and then create a database. I created a controller for POST and GET requests on a vFabric server using spring SVM. I started with the spring SVM web aplication template. Im using spring tool suite.
I am new to spring so I'm still grasping the concepts of bean and controllers.
my servlet configuration files goes like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.spring.mongodb" />
</beans:beans>
Its basically a configuration I borrowed so I assume this is the problem.
the web.xml configuration goes like this:
<?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">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
and my main controller is this:
#Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
private static final Log log = LogFactory.getLog(HomeController.class);
private String bodyflow;
Coleccion Col;
#RequestMapping(value = "/", method = RequestMethod.POST)
public String getPOST(Locale locale, Model model, #RequestBody String body){
bodyflow = "char";
return "home";
}
#RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
model.addAttribute("postRequest", bodyflow );
return "home";
}
}
The problem with this code is that whereas the GET request is receive and executed by the method "home", the method getPOST does not execute, I assume it does not get the POST request and it I send to my server from the simple REST client google chrome. I assume is a configuration problem, do I need to add a diferent configuration to GET and POST?
You will notice that in the getPOST method I only set a variable, this is because I was testing if the problem was the model File being diferent in each method, but I realized the method isnt even running.
if you know of a better way of doing this please post it.
Thanks!
This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 6 years ago.
I'm absolutely newbie with Java and Spring and I want to learn from example.
I'm using an out-of-the-box configuration / installation
Mac OSX
Springsource Tool Suite as IDE
Spring 2.8.1.RELEASE
vfabric-tc-server-developer-2.6.1.RELEASE
I've tried to generate a new project based on "Spring Template Project". Then I've chosen the "Spring MVC Project". The sample project is generated. After that, without modifying anything, I've tried to execute de "home.jsp" page via "Run As". The Web Server starts and finally I received the error in the console Tab.
No mapping found for HTTP request with URI [/myproject/] in
DispatcherServlet with name 'appServlet'
And this other output in these web pages:
http://localhost:8080/myproject/WEB-INF/views/home.jsp
http://localhost:8080/myproject
Here you can see an image on how my project is structured (auto generated for STS):
What is wrong?
Here you can see the content of the web.xml file:
<?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">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
The root-context.xml file has this content.
<?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-3.0.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
</beans>
And finally the servlet-context.xml has this content.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
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">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.mycompany.myapp" />
</beans:beans>
Does anybody have an idea to solve it?
Spring's convention is to assume that the <servlet-name> in the web.xml for the DispatcherServlet matches the beginning of the Spring servlet context XML file. Rename servlet-context.xml to appServlet-context.xml and see if that helps.
Everything under WEB-INF is not accessible from the outside, and the point of an MVC framework is to invoke a controller before dispatching to the view, so invoking the JSP directly should not be done anyway.
And you probably don't have any Spring controller mapped to the root URL, so obviously, there is nothing at the URL http://localhost:8080/myproject/.
Add a Controller to your application that returns a ModelAndView instance with name "home". Then configure some handler mapping to that Controller and try to access your web app with a URL similar to this one: http://localhost:8080/myproject/home.do. More information can be found here and here.