File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Hello World Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Hello World" Watch "Hello World" New topic

Hello World

Amir Maddah

Joined: Aug 13, 2012
Posts: 1
Hi I am new to Sping MVC framework and tried to create my first application as following but once it get to help.html shows an error message stating that the resource has not been found. please help me thanks
I am using TomCat 7 as my server and Eclipse jee-jiuno as IDE

Dispatcher_servlet.xml located in webContent -> web_INF

<?xml version="1.0" encoding="UTF-8"?>






<bean id="viewResolver"

class="org.springframework.web.servlet.view.Intern alResourceViewResolver">

<property name="prefix">



<property name="suffix">




<bean id="urlMapping"

class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">

<property name="interceptors">


<ref local="localeChangeInterceptor"/>



<property name="urlMap">


<entry key="/hello.html">

<ref bean="helloController"/>





<bean id="helloController" class="World.HelloWorldController"></bean>

<bean id="localeChangeInterceptor" class="
org.springframework.web.servlet.i18n.LocaleChangeI nterceptor">

<property name="paramName" value="hl"/>


<bean id="localeResolver" class="org.springframework.web.servlet.i18n.Sessio nLocaleResolver"/>


Web.xml located in WebContent -> Web_Inf

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4"
xsi:schemaLocation="" >



<servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>











Index.jsp located in WebContent

<%@ page contentType="text/html" pageEncoding="UTF-8" %>

Hello World

hello.jsp located in WebContent -> Web_INF -> jsp
<%@ page contentType="text/html" pageEncoding="UTF-8" %>




HelloWorldController located in Java Resources -> src -> World

package World;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class HelloWorldController implements Controller {

public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

String Mess = "Hello World!";

ModelAndView modelAndView = new ModelAndView("hello");
modelAndView.addObject("message", Mess);

return modelAndView;

Thanks in Advance
Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

Please read UseCodeTags and BeForthrightWhenCrossPostingToOtherSites you have also posted this question here:

I would say you need to find a better tutorial for learning Spring MVC this one has some issues. I suggest you download STS

STS is eclipse with all the Spring stuff bundled. Once you download it go to File -> new Spring Template Project -> Spring MVC Project

This will generate a nice little hello world MVC app for you to get an idea of how it should be done.

[How To Ask Questions][Read before you PM me]
I agree. Here's the link:
subject: Hello World
It's not a secret anymore!