Announcement Announcement Module
Collapse
No announcement yet.
Multiple forms on one view? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Hey I m new to Spring...

    I tried the same what Chris suggested....

    1) Made 3 controllers each with a different form view.
    2) the form view of the 3rd contains the form tag<form > with a get method and the action pointing to the url of the other 2 forms..The 2 child controllers have a redirect to the parent form url....

    however the display view (the parent view )I get comes up to be blank and the child views do not get populated...Though I do not get any error ...can u please suggest whats that i may be missing out...Thanks
    Last edited by saakshi_jain; Jan 14th, 2012, 01:07 AM.

    Comment


    • #17
      redirect.jsp

      <%@page contentType="text/html" pageEncoding="UTF-8"%>
      <a href="user/add.do">Add</a>
      <br>
      <a href="user/remove.do">Remove</a>
      <br />
      <a href="abc.do?val1">val1</a>

      <form name="form1" action="abc.do" method="post">
      <input type="submit" value="val1" name="val1" />
      <input type="submit" value="val2" name="val2" />
      </form>
      ---------------------------------------------------
      web.xml file
      -------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>SpringMultiaccessController</display-name>
      <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>*.do</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
      <welcome-file>redirect.jsp</welcome-file>
      </welcome-file-list>
      </web-app>
      ------------------------------------------
      dispatcher-servlet.xml
      -----------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

      <bean id="viewResolver"
      class="org.springframework.web.servlet.view.Intern alResourceViewResolver"
      prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
      <context:component-scan base-package="com.vaannila.web" />
      </beans>
      --------------------------------------------------------------------
      abc.java controller
      ----------------------------------------------------------------------
      import org.springframework.stereotype.Controller;
      import org.springframework.web.bind.annotation.RequestMap ping;
      import org.springframework.web.bind.annotation.RequestMet hod;
      import org.springframework.web.servlet.ModelAndView;

      @Controller
      @RequestMapping(value="/abc.do")
      public class abc {

      @RequestMapping(params = "val1")
      public ModelAndView test() {

      return new ModelAndView("user", "message", "Index method called");
      }

      @RequestMapping(params = "val2", method = RequestMethod.POST)
      public ModelAndView submit()
      {
      return new ModelAndView("user", "message", "Submit method called");
      }

      }
      ----------------------------------------------------------------------------
      jsp/user.jsp
      -------------------------------------------------------
      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%>
      <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
      <!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>Registration Page</title>
      </head>
      <body>
      ${message}
      </body>
      </html>
      ---------------------------------------------------------------------

      Comment

      Working...
      X