Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC 3 project Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC 3 project

    I am building one application using eclispe Juno using spring MVC 3 structure.
    under src folder I have two pkg namely form and controller in which my form class which has fileds for web form and associated to formcontroller class which has request mapping for show and add forms.

    ContactForm.java
    package form;

    import java.util.HashMap;
    import java.util.Map;

    public class ContactForm {
    private Map<String, String> contactMap = new HashMap<String, String>();

    public Map<String, String> getContactMap() {
    return contactMap;
    }

    public void setContactMap(Map<String, String> contactMap) {
    this.contactMap = contactMap;
    }
    }

    ContactController.java
    package Controller;

    import java.util.HashMap;
    import java.util.Map;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.ModelAttri bute;
    import org.springframework.web.bind.annotation.RequestMap ping;
    import org.springframework.web.bind.annotation.RequestMet hod;
    import org.springframework.web.portlet.ModelAndView;
    import form.ContactForm;

    @Controller
    public class ContactController {
    private static Map<String, String> contactMap = new HashMap<String, String>();
    static {
    contactMap.put("name", "John");
    contactMap.put("lastname", "Lennon");
    contactMap.put("genres", "Rock, Pop");
    }

    @RequestMapping(value = "/show", method = RequestMethod.GET)
    public ModelAndView get() {

    ContactForm contactForm = new ContactForm();
    contactForm.setContactMap(contactMap);
    return new ModelAndView("add_contact" , "contactForm", contactForm);
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ModelAndView save(@ModelAttribute("contactForm") ContactForm contactForm) {
    return new ModelAndView("show_contact", "contactForm", contactForm);
    }
    }

    Spring-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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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/schem...ng-context.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:annotation-config />
    <context:component-scan base-package="controller.spring3.controllerform" />
    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
    </bean>
    </beans>

    web.xml
    <?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_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>InternalApp</display-name>
    <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.html</url-pattern>
    </servlet-mapping>
    </web-app>

    Console message:
    Jan 04, 2013 11:32:56 AM org.apache.catalina.core.AprLifecycleListener init
    INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Win dows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\Sys tem32\Wbem;C:\Windows\System32\WindowsPowerShell\v 1.0\;C:\Program Files\Intel\Services\IPT\;C:\Program Files\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files\Dell\Dell Data Protection\Access\Advanced\Wave\Gemalto\Access Client\v5\;C:\Program Files\Windows Live\Shared;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\OEM\DLLShared\;C:\Program Files\Common Files\Roxio Shared\OEM\DLLShared\;C:\Program Files\Common Files\Roxio Shared\OEM\12.0\DLLShared\;C:\Program Files\Roxio\OEM\AudioCore\;C:\Program Files\apache-maven-3.0.4\bin\;C:\Users\tarun.arora\Downloads\eclipse; ;.
    Jan 04, 2013 11:32:57 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:InternalApp' did not find a matching property.
    Jan 04, 2013 11:32:58 AM org.apache.coyote.AbstractProtocolHandler init
    INFO: Initializing ProtocolHandler ["http-bio-8080"]
    Jan 04, 2013 11:32:58 AM org.apache.coyote.AbstractProtocolHandler init
    INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
    Jan 04, 2013 11:32:58 AM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 2387 ms
    Jan 04, 2013 11:32:58 AM org.apache.catalina.core.StandardService startInternal
    INFO: Starting service Catalina
    Jan 04, 2013 11:32:58 AM org.apache.catalina.core.StandardEngine startInternal
    INFO: Starting Servlet Engine: Apache Tomcat/7.0.12
    Jan 04, 2013 11:33:04 AM org.apache.catalina.core.ApplicationContext log
    INFO: No Spring WebApplicationInitializer types detected on classpath
    Jan 04, 2013 11:33:04 AM org.apache.catalina.core.ApplicationContext log
    INFO: Marking servlet spring as unavailable
    Jan 04, 2013 11:33:04 AM org.apache.catalina.core.StandardContext loadOnStartup
    SEVERE: Servlet /InternalApp threw load() exception
    java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1521)
    at org.springframework.web.servlet.DispatcherServlet. <clinit>(DispatcherServlet.java:246)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.apache.catalina.core.DefaultInstanceManager.ne wInstance(DefaultInstanceManager.java:119)
    at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1062)
    at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:1010)
    at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContext.java:4935)
    at org.apache.catalina.core.StandardContext$3.call(St andardContext.java:5262)
    at org.apache.catalina.core.StandardContext$3.call(St andardContext.java:5257)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unkn own Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
    at java.lang.Thread.run(Unknown Source)

    Jan 04, 2013 11:33:04 AM org.apache.coyote.AbstractProtocolHandler start
    INFO: Starting ProtocolHandler ["http-bio-8080"]
    Jan 04, 2013 11:33:04 AM org.apache.coyote.AbstractProtocolHandler start
    INFO: Starting ProtocolHandler ["ajp-bio-8009"]
    Jan 04, 2013 11:33:04 AM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 6476 ms
Working...
X