Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

spring web

Ads

 
 

Share on Google+Share on Google+

samar
spring web
1 Answer(s)      5 years and 9 months ago
Posted in : Spring

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

Ads
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


Ads









Related Tutorials/Questions & Answers:
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
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
Advertisements
Version of spring>spring-web dependency
List of Version of spring>spring-web dependency
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 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 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 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
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
Spring web UrlBasedViewResolver
Spring web UrlBasedViewResolver...;org.springframework.web.servlet.view.JstlView" /> <property name="prefix"> <value>/WEB...://www.springframework.org/schema/beans/spring-beans-3.0.xsd http
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
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.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
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.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.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.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-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.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.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.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.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.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-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.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