SpringMvc注册登录项目实战一

注册登录系统

版本说明

  • eclipse
  • jdk1.8
  • Tomcat7.0.91
  • maven3.5.4

web.xml配置



  	SpringMvc-login

  	
	
		SpringMvc
		 org.springframework.web.servlet.DispatcherServlet
		  
		
    	 	contextConfigLocation
    	 	/WEB-INF/springmvc-config.xml 	
      	
	
	  
	 
	
		SpringMvc
		/
	

spring-mvc配置


        
   
    
    
    
    
        
        
           

pojo类

package pojo;

public class User {
	private String userName;//用户名,登录名
	private String password;
	private String fullName;//姓名
	
	public String getName() {
		return  userName;
	}
	
	public  void setUserName(String userName) {
		this.userName = userName;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getFullName() {
		return fullName;
	}
	
	public void setFullName(String fullName) {
		this.fullName = fullName;
	}
}

Controller控制类

package controller;

import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import pojo.User;

@Controller
@RequestMapping("/user")
public class UserController {
	private static List userList;
	{
		userList = new ArrayList();
	}
	/*注册页面*/
	@RequestMapping(value="/showRegUser")
	public String showRegUser() {
		return "regUser";
	}
	/*新增用户*/
	/*
	 * @RequestParam*/
	@RequestMapping(value="/addUser")
	public String addUser(
			@RequestParam("userName")String userName,
			@RequestParam("password")String password,
			@RequestParam("fullName")String fullName) {
		User user = new User();
		user.setUserName(userName);
		user.setPassword(password);
		user.setFullName(fullName);	
		userList.add(user);
		/*注册成功后跳转至注册页面*/
		return "login";
	}
	/*登录页面*/
	@RequestMapping(value="/showLogin")
	public String showlogin() {
		return "login";
	}
	/*验证用户*/ 
	@RequestMapping(value="validateUser")
	public String login(
			@RequestParam("userName")String userName,
			@RequestParam("password")String password,Model model) {
		//*到集合中查找用户是否存在
		for(User user:userList) {
			if(user.getName().equals(userName) && user.getPassword().equals(password)) {
				model.addAttribute("user",user);	
				return "welcome";
			}
		}
		//验证失败跳转到登录页面*/
		return "login";	
	}
}

初始界面index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




首页


	


注册页面register.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




用户注册


	

用户注册

登录界面login.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




登录页面


	

登录成功界面welcome.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




登录成功


 	登录成功


你可能感兴趣的:(SSM)