Announcement Announcement Module
Collapse
No announcement yet.
Hello World Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hello World

    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"?>

    <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-2.5.xsd"


    xmlns="http://www.springframework.org/schema/p">


    <bean id="viewResolver"


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


    <property name="prefix">


    <value>/WEB-INF/jsp/</value>


    </property>


    <property name="suffix">


    <value>.jsp</value>


    </property>


    </bean>


    <bean id="urlMapping"


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


    <property name="interceptors">


    <list>


    <ref local="localeChangeInterceptor"/>


    </list>


    </property>


    <property name="urlMap">


    <map>


    <entry key="/hello.html">


    <ref bean="helloController"/>


    </entry>


    </map>


    </property>


    </bean>


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

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


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


    </bean>


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

    </beans>


    Web.xml located in WebContent -> Web_Inf


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

    <web-app version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >

    <servlet>


    <servlet-name>dispatcher</servlet-name>


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


    <load-on-startup>1</load-on-startup>


    </servlet>


    <servlet-mapping>


    <servlet-name>dispatcher</servlet-name>


    <url-pattern>*.html</url-pattern>


    </servlet-mapping>


    <welcome-file-list>


    <welcome-file>index.jsp</welcome-file>


    </welcome-file-list>

    </web-app>


    Index.jsp located in WebContent


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

    <html>
    <body>
    <a href="hello.html">Hello World</a>
    </body>
    </html>

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

    <html>
    <body>

    <c:outvalue="${message}"/>

    </body>
    </html>

    HelloWorldController located in Java Resources -> src -> World

    package World;

    import java.io.IOException;

    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

  • #2
    Your deployment is not to find the View to be rendered from the right place.

    In your war or hot deployment on the tomcat you should have your view
    Code:
    /WEB-INF/jsp/hello.jsp
    Based on the controller your source for the controller should be in

    Code:
    World.HelloWorldController
    As
    resource has not been found
    indicates that the source is not in the right place for the container to render the output expected

    Comment

    Working...
    X