资源简介

ssm+maven用拦截器实现登录小Demo。下载资源里已经包含SQL文件。 演示地址:https://blog.csdn.net/kzw11/article/details/79940449

资源截图

代码片段和文件信息

package com.kze.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kze.entity.User;
import com.kze.service.Usersevice;


@Controller
public class Login {

@Autowired
private Usersevice userService;
public void setUserService(Usersevice userService) {
this.userService = userService;
}


@RequestMapping(“/toindex“)
public String toIndex(){
return “index“;//这里index我作为了登录界面
}

@RequestMapping(“/main“)
public String main(){
return “main“;//作为想要访问的目标界面
}
@RequestMapping(“/logout“)
public String logout(HttpSession session){
//清除session
session.invalidate();
return “redirect:index“;
}

@RequestMapping(“/login“)
    public String login(HttpServletRequest req HttpServletResponse resp){
System.out.println(“login 方法调用成功!“);
        String username=req.getParameter(“username“);
        String pwd=req.getParameter(“password“);
 System.out.println(username+“为用户名; 密码为:“+pwd);
        if(userService.verify(usernamepwd)){
            req.getSession().setAttribute(“user“userService.getUserByName(username));
            return “main“;
        }else{
         return “index“;
        }

    }

@RequestMapping(“/login2“)
public String index(){
System.out.println(“login123方法调用“);
return “login“;
}


@RequestMapping(“/login3“)
@ResponseBody
    public User testJson(@RequestBody User user){
System.out.println(“testJson 方法调用成功!“);
        
        User user2=userService.login(user);
        System.out.println(user2);
return user2;

    }

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        640  2018-04-07 18:05  ssmmavenlogindemo\.classpath

     文件        323  2018-04-07 18:12  ssmmavenlogindemo\.mymetadata

     文件       1936  2018-04-07 14:17  ssmmavenlogindemo\.project

     文件        508  2018-04-07 11:07  ssmmavenlogindemo\.settings\.jsdtscope

     文件        143  2018-04-13 21:38  ssmmavenlogindemo\.settings\com.genuitec.eclipse.core.prefs

     文件       1065  2018-04-07 14:35  ssmmavenlogindemo\.settings\com.genuitec.eclipse.j2eedt.core.prefs

     文件         93  2018-04-09 19:36  ssmmavenlogindemo\.settings\org.eclipse.core.resources.prefs

     文件        695  2018-04-07 14:31  ssmmavenlogindemo\.settings\org.eclipse.jdt.core.prefs

     文件        121  2018-04-07 11:07  ssmmavenlogindemo\.settings\org.eclipse.m2e.core.prefs

     文件        570  2018-04-07 18:12  ssmmavenlogindemo\.settings\org.eclipse.wst.common.component

     文件        252  2018-04-07 12:51  ssmmavenlogindemo\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件         49  2018-04-07 11:07  ssmmavenlogindemo\.settings\org.eclipse.wst.jsdt.ui.superType.container

     文件          6  2018-04-07 11:07  ssmmavenlogindemo\.settings\org.eclipse.wst.jsdt.ui.superType.name

     文件        978  2018-09-25 17:07  ssmmavenlogindemo\logindemo.sql

     文件       6316  2018-04-14 14:47  ssmmavenlogindemo\pom.xml

     文件       2179  2018-04-14 15:07  ssmmavenlogindemo\src\main\java\com\kze\controller\Login.java

     文件        775  2018-04-07 12:02  ssmmavenlogindemo\src\main\java\com\kze\entity\User.java

     文件       1519  2018-04-14 15:10  ssmmavenlogindemo\src\main\java\com\kze\interceptor\loginInterceptor.java

     文件        424  2018-04-14 14:57  ssmmavenlogindemo\src\main\java\com\kze\mapper\UserMapper.java

     文件       1059  2018-04-14 15:14  ssmmavenlogindemo\src\main\java\com\kze\service\UserServiceImpl.java

     文件        229  2018-04-13 22:52  ssmmavenlogindemo\src\main\java\com\kze\service\Usersevice.java

     文件        694  2018-04-14 14:07  ssmmavenlogindemo\src\main\java\log4j.properties

     文件       2793  2018-04-22 17:49  ssmmavenlogindemo\src\main\java\spring-mybatis.xml

     文件       2019  2018-04-14 14:51  ssmmavenlogindemo\src\main\java\springMVC-config.xml

     文件      95957  2018-04-13 21:38  ssmmavenlogindemo\src\main\webapp\js\jquery-1.11.3.min.js

     文件         36  2018-04-07 11:07  ssmmavenlogindemo\src\main\webapp\meta-INF\MANIFEST.MF

     文件       1082  2018-04-14 13:46  ssmmavenlogindemo\src\main\webapp\WEB-INF\jsp\index.jsp

     文件       2086  2018-04-14 12:15  ssmmavenlogindemo\src\main\webapp\WEB-INF\jsp\login.jsp

     文件        921  2018-04-14 13:33  ssmmavenlogindemo\src\main\webapp\WEB-INF\jsp\main.jsp

     文件        853  2018-04-09 18:32  ssmmavenlogindemo\src\main\webapp\WEB-INF\jsp\success.jsp

............此处省略61个文件信息

评论

共有 条评论