spring web

spring web

Hi can you explain the flow of spring web programatically.........

View Answers

October 18, 2011 at 12:42 PM

Hi at first please insert the all the relevant jar files in WEB-INF/lib directory, add the following servlet configuration in your web.xml file.

<servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

Now write the dispatcher-servlet.xml file and put it into the same directory as web.xml file.

In dispatcher servlet the main thing you have to do is to specify the path of the Controller class, as

<context:component-scan base-package="net.roseindia.controller" />

the following are the typical configurations in dispatcher-servlet.xml file

<?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:p="http://www.springframework.org/schema/p"
    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/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- Enable annotation driven controllers, validation etc... -->
    <mvc:annotation-driven />
    <context:component-scan base-package="net.roseindia.controller" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    </bean>
</beans>

Then write the form as

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<CENTER>
<h2>Please Enter Login Detail</h2>
<form:form action="loginForm.htm" commandName="loginForm">
    <table cellpadding="5" cellspacing="10" bgcolor="#00B8E6">
        <tr>
            <td><form:label path="userId">User Id</form:label></td>
            <td><form:input path="userId" /></td>
        </tr>
        <tr>
            <td><form:label path="password">Password</form:label></td>
            <td><form:password path="password" /></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="submit" value="Submit" /></td>
        </tr>

    </table>
</form:form></CENTER>

and corresponding bean class would be

package net.roseindia.model;

public class LoginForm {

    private String userId;
    private String password;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

And Now you need the write the controller class. The package wold be the same as you specified in the dispatcher-servlet.xml file i.e net.roseindia.controller

The controller class is given below please consider it..

package net.roseindia.controller;

import javax.validation.Valid;

import net.roseindia.model.LoginForm;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("loginForm.htm")
public class MyController {

    @RequestMapping(method = RequestMethod.GET)
    public String getRequest(ModelMap model) {
        LoginForm login = new LoginForm();
        model.put("loginForm", login);
        return "loginForm";
    }

    // @RequestMapping("loginForm.htm")
    @RequestMapping(method = RequestMethod.POST)
    public String postReQuest(ModelMap model, @Valid LoginForm login) {
        // LoginForm login = new LoginForm();
        model.addAttribute(login);
        System.out.println("Id- " + login.getUserId());
        System.out.println("Id- " + login.getPassword());
        model.put("loginForm", login);
        return "loginForm";
    }
}

Thanks









Related Tutorials/Questions & Answers:
spring web
spring web  Hi can you explain the flow of spring web programatically... in WEB-INF/lib directory, add the following servlet configuration in your web.xml... http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http
spring Web Services - Spring
spring Web Services  Hi, Can any one explains or give me some example which gives me that how to start up spring web services. Thanks, mahi
Advertisements
spring web - Spring
spring web  hi thanku for reply :) Actually i dint get u what is meaning of spring web as i understand i am telling you. I am using eclipse and jar files like spring.jar,tlds of spring. hibernet.jar and also required jars
Spring web service - Spring
Spring web service   Respected service, I have found an error in this manner(Connecting to tomcat then coming this error at first time only) and then working correctly. error coming only at first time. What
Version of spring>spring-web dependency
List of Version of spring>spring-web dependency
Web application - Spring
Web application  I need one simple complete web application example using springs with database connection,i saw ur demo but it is not succfient.can u send to [email protected] am a beginner
Version of springframework>spring-web dependency
List of Version of springframework>spring-web dependency
Spring Web, Spring Web Modules, Spring Web Example
Spring Web In this section we will discuss about the modules of Spring Web layer. The Spring Web modules allows the developers to develop/manage web... easier. The Spring Web Layer contains following modules: Web
Maven Repository/Dependency: spring | spring-web
Maven Repository/Dependency of Group ID spring and Artifact ID spring-web. Latest version of spring:spring-web dependencies. # Version... Tutorials What is Apache Maven? How to create Maven Web Application
Maven Dependency spring-web >> 1.0.2
You should include the dependency code given in this page to add Maven Dependency of spring >> spring-web version1.0.2 in your project
Spring web UrlBasedViewResolver
Spring web UrlBasedViewResolver...;org.springframework.web.servlet.view.JstlView" /> <property name="prefix"> <value>/WEB... http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http
Maven dependency for Spring Web MVC 4.0.1.RELEASE
Maven dependency for Spring Web MVC 4.0.1.RELEASE  Hi, What is the Maven dependency for Spring Web MVC 4.0.1.RELEASE? Thanks   Hi, You...; <groupId>org.springframework</groupId> <artifactId>spring
Spring Boot Web Starter 2.1.1 Maven dependency
Spring Boot Web Starter 2.1.1 Maven dependency  Hi, I want to use Spring Boot Web Starter 2.1.1 in my spring boot application. My application is based on the old version of Spring Boot. Now will use Spring Boot Web Starter 2.1.1
Maven Dependency spring-web >> 1.0
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.0 in your project
Maven Dependency spring-web >> 1.1
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.1 in your project
Maven Dependency spring-web >> 1.1.3
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.1.3 in your project
Maven Dependency spring-web >> 1.1-rc1
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.1-rc1 in your project
Maven Dependency spring-web >> 1.2.1
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.2.1 in your project
Maven Dependency spring-web >> 1.2.4
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.2.4 in your project
Maven Dependency spring-web >> 1.2-rc1
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.2-rc1 in your project
Maven Dependency spring-web >> 1.0.1
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.0.1 in your project
Maven Dependency spring-web >> 1.0-rc1
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.0-rc1 in your project
Maven Dependency spring-web >> 1.1.1
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.1.1 in your project
Maven Dependency spring-web >> 1.1.2
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.1.2 in your project
Maven Dependency spring-web >> 1.1.4
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.1.4 in your project
Maven Dependency spring-web >> 1.1.5
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.1.5 in your project
Maven Dependency spring-web >> 1.1-rc2
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.1-rc2 in your project
Maven Dependency spring-web >> 1.2
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.2 in your project
Maven Dependency spring-web >> 1.2.2
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.2.2 in your project
Maven Dependency spring-web >> 1.2.3
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.2.3 in your project
Maven Dependency spring-web >> 1.2.5
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.2.5 in your project
Maven Dependency spring-web >> 1.2.6
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.2.6 in your project
Maven Dependency spring-web >> 1.2-rc2
You should include the dependency code given in this page to add Maven Dependency of springframework >> spring-web version1.2-rc2 in your project
spring boot starter web maven dependency 2.0.0
spring boot starter web maven dependency 2.0.0  Hi, I want to use.... What is spring boot starter web maven dependency 2.0.0? Thanks   Hi...; The above code is for spring boot starter web maven dependency 2.0.0. Thanks
How to make web appliction using spring and hibernate - Spring
How to make web appliction using spring and hibernate  Hi Actually i want to make an web application using spring as front end and hibernate as back...  Hello,Are you using Spring web for developing the application
Spring web mvc 3.0 mysql project
Spring web mvc 3.0 mysql project  Hello Sir... I want a complete database connectivity web project in spring mvc 3.0..Just give me a simple example...: http://www.roseindia.net/spring/jdbc-template-batch-update.shtml
develope a web site using JSF,Spring,Hibernate.
develope a web site using JSF,Spring,Hibernate.  I have to develope a web site,just like Facebook,which will have all the functionality as wall post...,Spring Framework,Hibernate,JMS. Please anyone provide me idea,how to proceed ahead
Maven Repository/Dependency: springframework | spring-web
Maven Repository/Dependency of Group ID springframework and Artifact ID spring-web. Latest version of springframework:spring-web dependencies... What is Apache Maven? How to create Maven Web Application
Maven Repository/Dependency: cn.ipokerface | spring-web
Maven Repository/Dependency of Group ID cn.ipokerface and Artifact ID spring-web. Latest version of cn.ipokerface:spring-web dependencies... Maven Web Application in Eclipse? Maven 3 Tutorial Convert Maven project
Maven Repository/Dependency: org.springframework | spring-web
spring-web. Latest version of org.springframework:spring-web dependencies... is Apache Maven? How to create Maven Web Application in Eclipse? Maven 3 Tutorial Convert Maven project to Eclipse Web Project
org.springframework.security - spring-security-web version 4.2.0.RELEASE Maven dependency. How to use spring-security-web version 4.2.0.RELEASE in pom.xml?
; - Version 4.2.0.RELEASE of spring-security-web in pom.xml? How to use spring-security... 4.2.0.RELEASE of spring-security-web in project by the help of adding.... The developers of   org.springframework.security - spring-security-web
org.springframework - spring-web version 1.2.2 Maven dependency. How to use spring-web version 1.2.2 in pom.xml?
org.springframework  - Version 1.2.2 of spring-web Maven dependency? How to use  org.springframework  - Version 1.2.2 of spring-web in pom.xml? How to use spring-web version 1.2.2 in pom.xml? Learn to use this dependency
org.springframework - spring-web version 4.3.20.RELEASE Maven dependency. How to use spring-web version 4.3.20.RELEASE in pom.xml?
org.springframework  - Version 4.3.20.RELEASE of spring-web Maven... of spring-web in pom.xml? How to use spring-web version 4.3.20.RELEASE in pom.xml... org.springframework  - Version 4.3.20.RELEASE of spring-web in project by the help
org.springframework - spring-web version 4.3.8.RELEASE Maven dependency. How to use spring-web version 4.3.8.RELEASE in pom.xml?
org.springframework  - Version 4.3.8.RELEASE of spring-web Maven... of spring-web in pom.xml? How to use spring-web version 4.3.8.RELEASE in pom.xml? Learn... org.springframework  - Version 4.3.8.RELEASE of spring-web in project by the help
org.springframework.security - spring-security-web version 3.2.7.RELEASE Maven dependency. How to use spring-security-web version 3.2.7.RELEASE in pom.xml?
; - Version 3.2.7.RELEASE of spring-security-web in pom.xml? How to use spring-security... 3.2.7.RELEASE of spring-security-web in project by the help of adding.... The developers of   org.springframework.security - spring-security-web
org.springframework.security - spring-security-web version 3.0.5.RELEASE Maven dependency. How to use spring-security-web version 3.0.5.RELEASE in pom.xml?
; - Version 3.0.5.RELEASE of spring-security-web in pom.xml? How to use spring-security... 3.0.5.RELEASE of spring-security-web in project by the help of adding.... The developers of   org.springframework.security - spring-security-web
Getting HTTP 404 error in Spring web MVC with Hibernate Integration
Getting HTTP 404 error in Spring web MVC with Hibernate Integration   Hi, i am Getting HTTP 404 error in Spring web MVC with Hibernate Integration...;Please visit the following links: http://www.roseindia.net/struts/hibernate-spring
Maven Repository/Dependency: org.springframework.security | spring-security-web
and Artifact ID spring-security-web. Latest version of org.springframework.security:spring-security-web dependencies. # Version Release... Maven? How to create Maven Web Application in Eclipse? Maven 3
org.springframework.boot - spring-boot-starter-web version 1.2.4.RELEASE Maven dependency. How to use spring-boot-starter-web version 1.2.4.RELEASE in pom.xml?
1.2.4.RELEASE of spring-boot-starter-web in pom.xml? How to use spring-boot... 1.2.4.RELEASE of spring-boot-starter-web in project by the help of adding..., the released version of  org.springframework.boot - spring-boot-starter-web
org.springframework.boot - spring-boot-starter-web version 1.5.8.RELEASE Maven dependency. How to use spring-boot-starter-web version 1.5.8.RELEASE in pom.xml?
1.5.8.RELEASE of spring-boot-starter-web in pom.xml? How to use spring-boot... 1.5.8.RELEASE of spring-boot-starter-web in project by the help of adding..., the released version of  org.springframework.boot - spring-boot-starter-web

Ads