东软培训-004

昨天说的那个hibernate太简单了,所以就没发出来,今天教spring+springmvc

//LoginAction.java

package org.mo.spring;

import java.util.HashMap;
import java.util.Map;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class LoginAction extends SimpleFormController {

	private String fail_view;

	private String success_view;

	private int login(LoginInfo info) {
		if (!"".equals(info.getAccount()) && !"".equals(info.getPassword())) {
			if (UserInfo.exitsUser(info.getAccount())) {
				if (UserInfo.confirmPassword(info.getAccount(), info.getPassword())) {
					return 1;//登录成功
				} else {
					return 2;//用户密码不正确
				}
			} else {
				return 3;//用户不存在
			}
		} else {
			return 0;//填写信息有误
		}
	}

	@Override
	protected ModelAndView onSubmit(Object command, BindException errors)
			throws Exception {
		LoginInfo loginInfo = (LoginInfo) command;
		String message = null;
		Map<String, String> map = new HashMap<String, String>();
		if (login(loginInfo) == 0) {
			message = "用户名或密码为空";
			map.put("msg", message);
			return new ModelAndView(this.fail_view, map);
		} else if (login(loginInfo) == 3) {
			message = "用户不存在";
			map.put("msg", message);
			return new ModelAndView(this.fail_view, map);
		} else if (login(loginInfo) == 2) {
			message = "用户密码不正确";
			map.put("msg", message);
			return new ModelAndView(this.fail_view, map);
		} else {
			message = "登录成功";
			map.put("msg", message);
			return new ModelAndView(this.success_view, map);
		}
	}

	public String getFail_view() {
		return fail_view;
	}

	public void setFail_view(String fail_view) {
		this.fail_view = fail_view;
	}

	public String getSuccess_view() {
		return success_view;
	}

	public void setSuccess_view(String success_view) {
		this.success_view = success_view;
	}

}

//LoginInfo.java

package org.mo.spring;

public class LoginInfo implements java.io.Serializable {
	private String account;
	private String password;

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}

//UserInfo.java

package org.mo.spring;

import java.util.HashMap;
import java.util.Map;

public class UserInfo {
	private static Map<String, String> userInfo = new HashMap<String, String>();

	static {
		String user_one = "admin";
		String password_one = "123456";

		String user_two = "neusoft";
		String password_two = "neusoft";

		userInfo.put(user_one, password_one);
		userInfo.put(user_two, password_two);
	}

	public static boolean exitsUser(String username) {
		return userInfo.containsKey(username);
	}

	public static boolean confirmPassword(String username, String password) {
		return userInfo.get(username).endsWith(password);
	}
}

//applicationContext.xml

<?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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
						http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="loginAction" class="org.mo.spring.LoginAction">
	<property name="commandClass">
		<value>org.mo.spring.UserInfo</value>
	</property>
	<property name="fail_view">
		<value>/error.jsp</value>
	</property>
	<property name="success_view">
		<value>/main.jsp</value>
	</property>
</bean>
	<bean id="f" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="mappings">
			<props>
				<prop key="/login.do">loginAction</prop>
			</props>
		</property>
	</bean>
</beans>

//login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP ‘login.jsp‘ starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <form action="login.do" method="post">
    用户名:<input type="text" name="account"><br/>
   密&nbsp;码:<input type="password" name="password"><br/>
   <input type="submit" value="提交">
    </form>
  </body>
</html>

//error.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP ‘error.jsp‘ starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    很遗憾,登录失败,失败原因是<%=request.getAttribute("msg") %>
  </body>
</html>
时间: 2024-08-27 11:51:23

东软培训-004的相关文章

东软培训-003

继续上面的一篇文章 package org.mo.action; import java.util.List; import org.mo.DAO.UserJDBCDAO; import org.mo.model.UserModel; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { private List<UserModel> list; private

东软培训-001

1 vo层 javaBean 2 工具层 一类 数据库打开与关闭 3 DAO层 接口 4 实现层 实现类 5 代理层 6 工场层 7 JSP 8 servlet ============================================================= D:\Java\jdk1.7.0_67\bin\native2ascii 编码工具 ========================================================== 使用stru

东软培训-002

数据库操作 实体bean package org.mo.model; public class UserModel { private Integer id; private String name; private Integer age; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } p

【绝密外泄】风哥Oracle数据库DBA高级工程师培训视频教程与内部资料v0.1

由于是[绝密外泄]资料,防止被查,需要的小伙伴赶紧下载附件中的课件文档. 由于视频太大了,已放在百度网盘了,已经在附中说明,以免被和谐. ---------------------------------------------- 第一部分:Oracle视频压缩包目录列表 ---------------------------------------------- 01.[绝密外泄]风哥全套Oracle数据库DBA高级工程师培训教程-视频分章节(不断更新) 02.[绝密外泄]风哥全套Oracle

web前端培训机构哪家好?

AAA教育课程设计引进北美先进技术,贴近中国软件企业的实际需求,同时,聘请北美海外专家与来自IBM.华为.用友.亚信.东软等国内外名企的一线实战专家担任讲师,以确保高端培训效果.AAA教育在课程设计与培训模式上不断创新,开创"零首付.低押金,就业后付款"的就业模式,改革培训模式保持培训规模扩大的同时确保90%以上的就业率,同时高质量就业. AAA教育在线在西安.沈阳.重庆.襄樊.长沙.深圳等全国各地,都设有人才服务外包基地,合作院校上千家,合作单位上万家,在校生上万人,培养出一批又一批

android内部培训视频_第四节(1)_异步网络操作

第四节(1):异步网络操作  一.结合asyncTask下载网络图片 1.定义下载类,继承自asyncTask,参数分别为:String(url地址),Integer(刻度,本例没有用到),BitMap(下载成功后的图片) public class downloadImageTask extends AsyncTask<String, Integer, Bitmap> { /** * 在线程开始之前执行 */ @Override protected void onPreExecute() {

Linux培训教程 linux中nl命令使用介绍

nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等等的功能.兄弟连linux培训 小编介绍一下:linux中 nl 命令使用介绍. 1.命令格式: nl [选项]... [文件]... 2.命令参数: -b :指定行号指定的方式,主要有两种: -b a :表示不论是否为空行,也同样列出行号(类似 cat -n); -b t :如果有空行,空的那一行

东软 内部员工离职述说

怀着对软件的梦想,我来到了东软 从看到沈阳园区的第一眼起,我就深深喜欢上了这里,大气磅礴壮美的园区洋溢的是宁静和谐的气氛 当时真的觉得东软和宣传的一样简单.务实.美 起初很喜欢东软那种学校的氛围文化,但是不知道是因为我来到这里后发现的事实真相越来越多.还是因为东软真的变质了,我真的开始厌恶这里 本来作为一个东软的员工,我一向认为那个公司都有自己黑暗的一面,而且员工不应该说公司的不好,那样的话岂非自煽耳光证明自己选择的错误 现在我要离开这里了,带着破灭的梦想和伤心,可能还有稍许的愤慨,发表此文权当

第一天的培训

今天是我们培训的第一天,作为初入IT类型的学习,讲师给我们说了很多,关于它的发展时间,前景还有许多他自身所经历的,但是毕竟是第一天,给我们讲的是让我们有个大概的了解和方向.当初对培训机构抱有很多疑问,虽然口口声声说的是可以给分配工作,可我对这里能学到的知识和能用到的方向更加期待,毕竟谁都希望自己以后的工作成果能得到更多人的使用和赞同,以及能有个长远的发展前景.      第一天的课程基本算是以熟悉这个行业为主吧,没有什么可以写的,以后估计就会是每天学习内容的总结或者是理解,将会有一堆的代码吧.希