Results 1 to 3 of 3

Thread: SpringFormController HELP NEEDED IMMEDIATELY

  1. #1

    Default SpringFormController HELP NEEDED IMMEDIATELY

    Something trivial that I am not getting. :-)

    Here is my web.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" 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">
    <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.Log4jConfigList ener</listener-class>
    </listener>
    
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    
    <servlet>
    <servlet-name>dispatch</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
    <servlet-name>dispatch</servlet-name>
    <url-pattern>/send/*</url-pattern>
    </servlet-mapping>
    
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>

    Here is my very basic controller:


    Code:
    package com.memestorm.web;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.validation.BindException;
    import org.springframework.web.context.support.WebApplica tionContextUtils;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.SimpleFormCont roller;
    import org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController;
    
    
    
    public class DispatchController extends SimpleFormController {
    
    public DispatchController(){
    super();
    setCommandClass(Product.class);
    setFormView("edit");
    }
    
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
    Object command, BindException errors) throws Exception {
    System.out.print(command);
    return new ModelAndView("result");
    }
    
    }

    Here is my web application context (dispatch-servlet.xml):


    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
    <bean id="bigBrotherHandlerInterceptor"
    class="com.memestorm.web.BigBrotherHandlerIntercep tor" />
    
    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="prefix">
    <value>/WEB-INF/views/</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="bigBrotherHandlerInterceptor"/>
    </list>
    </property>
    <property name="mappings">
    <props>
    <prop key="/edit.html">dispatchController</prop>
    </props>
    </property>
    </bean>
    
    <bean id="dispatchController"
    class="com.memestorm.web.DispatchController">
    </bean>
    
    </beans>
    Here is the viewform (edit.jsp):

    Code:
    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
    <%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
    
    <%
    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>
    
    <form 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">${status.errorMessage}</span>
    </spring:bind>
    </td>
    </tr>
    <tr>
    <td>
    Description
    </td>
    <td>
    <spring:bind path="command.description">
    <input name="description" value="${status.value}">
    <span class="error">${status.errorMessage}</span>
    </spring:bind>
    </td>
    </tr>
    
    <tr>
    <td></td>
    <td>
    <input type="submit">
    </td>
    </tr>
    
    </table>
    
    </form>
    
    </body>
    </html>
    Here is the simple result page:


    Code:
    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPor t()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'result.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>
    Your data has been submitted. <br>
    </body>
    </html>

    Here is the URL I use to view the form:

    localhost:8080 /SpringProj2 /send /edit.html

    My browser is redirected to this url after i hit the submit button:
    //localhost:8080/ SpringProj2/ edit.html where Tomcat complains it can't find the requested resource.

    Note: I have tried to change /send/* to /* in the web.xml at which point it won't even render the form. I can't figure it out. Can you see where I am messing up? Thanks.

  2. #2
    Join Date
    Nov 2007
    Location
    Sun Prairie, WI
    Posts
    50

    Default

    You have all your JSPs under /WEB-INF/views/ directory right??
    satsranchuser

  3. #3

    Default hi

    I too got the same issue

Posting Permissions

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