facebook

SimpleFormController example will not work in spring 2.0

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #291546 Reply

    awebpro
    Member

    I am using ProSpring book and trying out an example that they gave me for simpleFormController. It does not work. Reading other books, I don’t find anything particularly wrong. Can someone spot what’s wrong here?

    The error I get is:
    WARN [org.springframework.web.servlet.PageNotFound] – No mapping for [/SpringProj2/views/edit.jsp] in DispatcherServlet with name ‘dispatch’

    when I type in the url in the browser:
    http://localhost:8080/SpringProj2/edit.htm

    Here is my dispatch-servlet.xml file:
    <?xml version=”1.0″ encoding=”UTF-8″ ?>
    <!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”&gt;

    <beans>

    <bean id=”viewResolver”
    class=”org.springframework.web.servlet.view.InternalResourceViewResolver”>
    <property name=”viewClass” value=”org.springframework.web.servlet.view.JstlView”/>
    <property name=”prefix”>
    <value>/views/</value>
    </property>
    <property name=”suffix”>
    <value>.jsp</value>
    </property>
    </bean>

    <bean id=”urlMapping”
    class=”org.springframework.web.servlet.handler.SimpleUrlHandlerMapping”>
    <property name=”mappings”>
    <props>
    <prop key=”/edit.html”>productFormController</prop>
    <prop key=”/edit.htm”>productFormController</prop>
    </props>
    </property>
    </bean>

    <bean id=”productFormController”
    class=”com.memestorm.web.ProductFormController”>
    </bean>

    </beans>

    Here is web.xml:
    <?xml version=”1.0″ encoding=”UTF-8″?>
    <web-app id=”WebApp_ID” version=”2.4″ xmlns=”http://java.sun.com/xml/ns/j2ee&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”&gt;
    <display-name>foo</display-name>

    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
    </context-param>
    <context-param>
    <param-name>log4jRefreshInterval</param-name>
    <param-value>1000</param-value>
    </context-param>

    <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
    <servlet-name>dispatch</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>dispatch</servlet-name>
    <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>

    Here is the controller:
    package com.memestorm.web;

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

    import org.springframework.validation.BindException;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.SimpleFormController;

    public class ProductFormController extends SimpleFormController {

    public ProductFormController() {
    super();
    setCommandClass(Product.class);
    setFormView(“edit”);
    setSuccessView(“newedit”);

    }

    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
    Object command, BindException errors) throws Exception {

    System.out.println(“command”);
    return new ModelAndView(“products-index”);
    }

    }

    Here is edit.jsp:
    <%@ page language=”java” import=”java.util.*” pageEncoding=”ISO-8859-1″%>
    <%@taglib prefix=”c” uri=”http://java.sun.com/jstl/core&#8221; %>
    <%@taglib prefix=”spring” uri=”http://www.springframework.org/tags&#8221; %>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
    %>

    <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
    <html>
    <head>
    <base href=”<%=basePath%>”>

    <title>My JSP ‘edit.jsp’ starting page</title>

    <meta http-equiv=”pragma” content=”no-cache”>
    <meta http-equiv=”cache-control” content=”no-cache”>
    <meta http-equiv=”expires” content=”0″>
    <meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
    <meta http-equiv=”description” content=”This is my page”>
    <!–
    <link rel=”stylesheet” type=”text/css” href=”styles.css”>
    –>

    </head>

    <body>
    <br>This is my JSP page. <br>
    <form name=”edit” action=”edit.html” method=”post”>
    <table>
    <tr>
    <td>Name</td>
    <td><spring:bind path=”command.name”>
    <input name=”name” value=”${status.value}”/>
    <span class=”error”><c:out value=”${status.errorMessage}”/></span>
    </spring:bind>
    </td>
    </tr>
    <tr>
    <td>Price</td>
    <td><spring:bind path=”command.price”>
    <input name=”price” value=”${status.value}”/>
    <span class=”error”><c:out value=”${status.errorMessage}”/></span>
    </spring:bind>
    </td>
    </tr>

    <tr>
    <td>
    <input type=”submit”>
    </td>
    </tr>
    </table>

    </form>
    </body>
    </html>

    #291576 Reply

    Loyal Water
    Member

    Moving to Off Topic >> Software Development.

    #291625 Reply

    awebpro
    Member

    anybody figure this out?

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: SimpleFormController example will not work in spring 2.0

You must be logged in to post in the forum log in