东软培训-001

1 vo层 javaBean

2 工具层 一类 数据库打开与关闭

3 DAO层 接口

4 实现层 实现类

5 代理层

6 工场层

7 JSP

8 servlet

=============================================================

D:\Java\jdk1.7.0_67\bin\native2ascii 编码工具

==========================================================

使用struts实现登录

//vo层

package org.mo.vo;

public class User implements java.io.Serializable {
	
	private String account;
	
	private String password;
	
	private String repassword;
	
	private String sumbitTag;

	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;
	}

	public String getRepassword() {
		return repassword;
	}

	public void setRepassword(String repassword) {
		this.repassword = repassword;
	}

	public String getSumbitTag() {
		return sumbitTag;
	}

	public void setSumbitTag(String sumbitTag) {
		this.sumbitTag = sumbitTag;
	}

}

//struts文件配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<constant name="struts.devMode" value="true"/>
	<constant name="struts.locale" value="zh_CN"/>
	<constant name="struts.i18n.encoding" value="UTF-8"/>
	
	<package name="mo" extends="struts-default" namespace="/">
		<action name="login" class="org.mo.action.Login">
			<result name="towelcome">/welcome.jsp</result>
			<result name="input">/login.jsp</result>
		</action>
	</package>
</struts>

//controller层
package org.mo.action;

import org.mo.vo.User;

import com.opensymphony.xwork2.ActionSupport;

public class Login extends ActionSupport {

	private User user;

	@Override
	public String execute() throws Exception {
		return "towelcome";
		// Login.properties
	}

	@Override
	public void validate() {
		if (user.getAccount().trim().length() == 0) {
			this.addFieldError("account", this.getText("account"));
		}
		if (user.getPassword().trim().length() == 0) {
			this.addFieldError("password", this.getText("password"));
		}
		if (user.getPassword().trim().length() <= 6) {
			this.addFieldError("password2", this.getText("password2"));
		}
		super.validate();
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}

//Login.properties
account=\u7528\u6237\u540D\u4E0D\u80FD\u4E3A\u7A7A
password=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A
password2=\u5BC6\u7801\u4E0D\u80FD\u5C0F\u4E8E6\u4F4D

//login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	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">
	-->
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>

<body>
	<div class="container">
		<div class="row">
			<div class="col-xs-6 col-md-4">
				<s:if test="hasFieldErrors()">
					<s:iterator value="fieldErrors">
						<div class="alert alert-danger alert-dismissible fade in">
							<button type="button" class="close" data-dismiss="alert">
								<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
							</button>
							<s:property value="value[0]" />
						</div>
					</s:iterator>
				</s:if>

				<form action="login" method="post" role="form">
					<input type="hidden" name="user.sumbitTag" value="login">
					<div>帐号:</div>
					<input type="text" name="user.account" class="form-control"><br />
					<div>密码:</div>
					<input type="password" name="user.password" class="form-control"><br />
					<hr />
					<input type="submit" value="提交" class="btn btn-default">
				</form>
			</div>
		</div>
	</div>

</body>
</html>

项目截图

东软培训-001

你可能感兴趣的:(东软培训-001)