已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Spring MVC 入门实战-用一个简单的登录功能带你走上Spring MVC的大道上。本次工程结构图非常简陋的登录界面:Spring 视图层_viewindex.jsp base href= My JSP index.jsp starting page !- 用户名:密码: error.jsp base href= My JSP error.jsp starting page !- 用户名:密码: 登录失败 , success.jsp base href= My JSP success.jsp starting page !- 恭喜:,登录成功 Spring 控制层_controlLoginController.javapackage com.spring.controller;import java.util.HashMap;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.Controller;import com.spring.model.UserInfoBean;public class LoginController implements Controller private String successPage;private String errorPage;/private UserInfoBean userInfoBean;public String getSuccessPage() return successPage;public void setSuccessPage(String successPage) this.successPage = successPage;public void setErrorPage(String errorPage) this.errorPage = errorPage;private String getErrorPage() return errorPage;public ModelAndView handleRequest(HttpServletRequest request,HttpServletResponse response) throws Exception String username=request.getParameter(username); String password=request.getParameter(password); String message=null; if(username=null|password=null|username.trim().equals()|password.trim().equals() message= 用户名或者密码为空; Map model=new HashMap(); model.put(msg, message); return new ModelAndView(getErrorPage(),model); if(!UserInfoBean.exisitUser(username)message=username+不存在; Map model=new HashMap(); model.put(msg, message); return new ModelAndView(getErrorPage(),model);if(!UserInfoBean.confirmPassword(username,password)message=username+密码不正确;Map model=new HashMap(); model.put(msg, message); return new ModelAndView(getErrorPage(),model);elseMap model=new HashMap();model.put(username,username);return new ModelAndView(getSuccessPage(),model);Spring 模型层_modelUserInfoBean.javapackage com.spring.model;import java.util.HashMap;import java.util.Map;public class UserInfoBean private static Mapuserinfo=new HashMap();staticString numberOneUser=zhangsan;String numberOnePassword=123;String numberTwoUser=lisi;String numberTwoPassword=456;userinfo.put(numberTwoUser, numberTwoPassword);userinfo.put(numberOneUser, numberOnePassword);/判断一个用户名是否存在public static boolean exisitUser(String username)return userinfo.containsKey(username);public static boolean confirmPassword(String username,String password)return userinfo.get(username).equals(password);Spring 配置文件:Web.xml这里配置spring 的后台servletdispatcherServletorg.springframework.web.servlet.DispatcherServlet指定spring配置文件的路径contextConfigLocation/WEB-INF
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 湖南省衡阳市衡阳县第四中学2026-2027学年高三上学期开学考试数学试卷(含答案)
- 2026年佛山市顺德区公务员人员招聘笔试备考试题及答案详解
- 2026年朔州市朔城区公务员人员招聘考试参考题库及答案详解
- 2025年赤峰市松山区事业单位人员招聘笔试试题及答案详解
- 2026年长沙市雨花区公务员人员招聘笔试备考题库及答案详解
- 2025-2026学年大班种花说课稿
- 2025-2026学年备课说课稿网站app
- 2025年甘肃省兰州市公务员人员招聘笔试试题及答案详解
- 2025-2026学年ps的讲课说课稿
- 2026年湖南省岳阳市公务员人员招聘考试备考题库及答案详解
- 江苏南京市2027届高三上学期9月学情调研政治试卷(含解析)
- 2026年道路运输企业主要负责人理论考试题及答案
- 2026年度广东省珠海市交通事故人身损害赔偿标准和计算公式
- 2026润滑油行业人力资源需求变化与人才培养策略报告
- ★司法鉴定程序通则-自2026年5月1日起施行
- 骨折病理性骨折处理指南
- 八年级劳动国家质量监测考试模拟卷(四)
- 2025年工会社会工作者招聘笔试题目及解析答案
- (正式版)DB65∕T 4767-2024 《普通国省干线公路服务设施建设技术规范》
- 人体毒垢与健康
- 肘关节超声病变的超声诊断与评估
评论
0/150
提交评论