SPRINGMVC Login Demo

Source: Internet
Author: User

Introduction: Recently working on the spring of the MVC, have not touched before, feel very strange. Today a little idle on the internet to find a bit of information learning, is also a success! I've been using Struts2 's MVC before, in contrast, I prefer spring's MVC. In short, each has its own merits! Let's see how you can use it.

Here's a simple login demo I wrote based on spring MVC.

Project Overview Chart:


The following is a simple look at the specific code:

Xml:

<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">  <display-name></display-name>  < welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list>  <servlet>   <servlet-name>springMVC</servlet-name>   <servlet-class> Org.springframework.web.servlet.dispatcherservlet</servlet-class>   <load-on-startup>1</ load-on-startup>  </servlet>  <servlet-mapping>   <servlet-name>springmvc</ servlet-name>   <url-pattern>/</url-pattern><!--means intercept all requests-  </servlet-mapping ></web-app>
Springmvc-servlet.xml:

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p" xmlns: Mvc= "Http://www.springframework.org/schema/mvc" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/bean S/spring-beans-3.0.xsd Http://www.springframework.org/schema/context Http://www.spri                    Ngframework.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 "> <mvc:annotation-d Riven/> <!--annotation Resource Scan package path--<context:component-scan base-package= "Com.controllers"/> <be An class= "Org.springframework.web.servlet.mvc.annotation.DefAultannotationhandlermapping "/> <bean class=" Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter "/> <!--configuration View Resolver--< Bean id= "Viewresolver" class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property                   Name= "prefix" value= "/web-inf/pages/"/> <property name= "suffix" value= ". jsp"/> </bean>                  </beans>
TestController:

Package Com.controllers;import Javax.servlet.http.httpservletrequest;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.requestmapping;import com.models.Student; @Controller @requestmapping ("/test") public class TestController {@RequestMapping (value = "/test") Public String Test (HttpServletRequest request) {Student s = new Student (); System.out.println ("name===" + s.getname ()); System.out.println ("password===" + S.getpassword ()); String userName = Request.getparameter ("UserName"); String userpwd = Request.getparameter ("Userpwd"), Request.setattribute ("UserName", UserName), if (S.getname (). Equals ( UserName) && S.getpassword (). Equals (userpwd) {   return "success";}   return "Fail";}}

As for the JSP inside the code will not show, interested can go directly to download the case, the spring inside the package is complete, can be run directly, I hope that the same as my beginner help!

Demo Address: http://download.csdn.net/detail/javaweiming/7839841








SPRINGMVC Login Demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.