Results 1 to 2 of 2

Thread: Newbie in Spring FrameWork Please Help ...

  1. #1
    Join Date
    Jul 2012
    Posts
    1

    Smile Newbie in Spring FrameWork Please Help ...

    Hi ...

    My Company gives me a task to learn about Spring Framework MVC and ORM Modules and evaluate if we can implement it in our tasks in the future ..

    i began with code :
    Code:
    <servlet>
      	<servlet-name>springapp</servlet-name>
      	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      	<load-on-startup>1</load-on-startup>
      </servlet>
      
      <servlet-mapping>
      	<servlet-name>springapp</servlet-name>
      	<url-pattern>*.htm</url-pattern>
      </servlet-mapping>
    Code:
    <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 name="hello.htm" class="springapp.web.HelloController" >
    		
    	</bean>
    </beans>
    Code:
    package springapp.web;
    
    import javax.servlet.http.*;
    import javax.servlet.ServletException;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.Controller;
    
    import org.apache.commons.logging.LogFactory;
    import org.apache.commons.logging.Log;
    
    import java.io.IOException;
    import java.util.Date;
    
    public class HelloController implements Controller{
    
    	protected Log logger = LogFactory.getLog(getClass());
    	@Override
    	public ModelAndView handleRequest(HttpServletRequest request,
    			HttpServletResponse response) throws IOException, ServletException {
    		
    		
    		String now = (new Date()).toString();
    		logger.info("======== to Hello.jsp modle it then view it "+now+"===");
    		return new ModelAndView("hello.jsp", "now", now);
    	}
    	
    	
    
    }
    Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
        <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    
    <!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>Insert title here</title>
    </head>
    <body>
    	<h1>Spring Tutorial</h1>
    	<p>Greetings <c:out value="${now}"></c:out></p>
    </body>
    </html>
    and the result when i run the url "http:localhost:8080/SpringApp/hello.htm" is

    Code:
    org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/SpringApp/hello.htm] in DispatcherServlet with name 'springapp'

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    I suggest a read of the reference guide especially the web section.

    In short your bean name is wrong it should be prefixed with a / .
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •