本项目会运用到ServlectJspmysqlhtmlcss3.MVC三层架构采用了几种架包。
第一部分:解释MVC架构的名称。
MVC全名是Model View Controller,<br> 是 @@1模型(model)<br> @@2-视图(view)<br> @@3-控制器(controller)的缩写,<br> 一种软件设计典范,<br> 用一种业务逻辑、数据、界面显示分离的方法组织代码,<br> 将业务逻辑聚集到一个部件里面,在改进和个性化定制界面及用户交互的同时,<br> 不需要重新编写业务逻辑。<br> MVC被独特的发展起来用于映射传统<br> 的输入、处理和输出功能在一个逻辑<br> 的图形化用户界面的结构中。<br>
之前说的课都是为这一章坐下伏笔的。
首先看项目结构图
?第一模块是src下要建的类名。和包名。
?
第二部分运行结果图的展示。
?
?
?
?注册失败后返回的页面如上图所示。
成功后跳到登录页面
?登录成功的页面展示
这又是整个项目的流程展示内容。
?
第三部分:MVC三层架构的图解。
?上面图解的代码在下面
package com.student.controller;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.student.service.IStudentService;
import com.student.service.StudentServiceImp;
/**
* Servlet implementation class HomeServlet
*/
@WebServlet("/HomeServlet")
public class HomeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HomeServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//将浏览器的任务接收,发给业务逻辑层处理
IStudentService service=new StudentServiceImp();
List<Map<String, Object>> oList=service.getStudents();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
package com.student.service;
/**
* 业务逻辑层处理学生表功能的接口
* @author admin
*
*/
import java.util.List;
import java.util.Map;
public interface IStudentService {
//获取数据库中学生表中的所有学生信息
List<Map<String, Object>> getStudents();
}
package com.student.service;
import java.util.List;
import java.util.Map;
import com.student.dao.IStudentDao;
import com.student.dao.StudentDaoImp;
/**
* 业务逻辑层操作学生表功能的实现类
* @author admin
*
*/
public class StudentServiceImp implements IStudentService {
@Override
public List<Map<String, Object>> getStudents() {
IStudentDao dao=new StudentDaoImp();
return dao.getStudents();
}
}
package com.student.dao;
/**
* 数据访问层操作学生表的接口
* @author admin
*
*/
import java.util.List;
import java.util.Map;
public interface IStudentDao {
//接收业务逻辑层的任务,查询出所有学生信息
List<Map<String, Object>> getStudents();
}
package com.student.dao;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import com.student.utils.DBUtil;
/**
* 数据访问操作学生表的实现类
* @author admin
*
*/
public class StudentDaoImp implements IStudentDao {
@Override
public List<Map<String, Object>> getStudents() {
String sql="select * from tb_student2";
return DBUtil.jt.queryForList(sql);
}
}
?
上面图解的代码在下面。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学生信息对话列表</title>
<style type="text/css">
*{
background: linear-gradient(to right,red,pink,blue);
font-size:30px;
font-weight: bold;
}
</style>
</head>
<body>
<!-- 使用表格展示从数据库中获取的所有学生信息 -->
<div align="center">
<table border="2" style="width: 800px;text-align: center;border-collapse: collapse;">
<caption>学生信息列表</caption>
<tr>
<th>学号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
</tr>
<c:forEach items="${students}" var="stu">
<tr>
<td>${stu.id}</td>
<td>${stu.name}</td>
<td>${stu.age}</td>
<td>${stu.sex}</td>
</tr>
</c:forEach>
</table>
</div>
<h3 style="color:white; background: black;">
MVC全名是Model View Controller,<br>
是
@@1模型(model)<br>
@@2-视图(view)<br>
@@3-控制器(controller)的缩写,<br>
一种软件设计典范,<br>
用一种业务逻辑、数据、界面显示分离的方法组织代码,<br>
将业务逻辑聚集到一个部件里面,在改进和个性化定制界面及用户交互的同时,<br>
不需要重新编写业务逻辑。<br>
MVC被独特的发展起来用于映射传统<br>
的输入、处理和输出功能在一个逻辑<br>
的图形化用户界面的结构中。<br>
</h3>
</body>
</html>
package com.student.controller;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.student.service.IStudentService;
import com.student.service.StudentServiceImp;
/**
* Servlet implementation class HomeServlet
*/
@WebServlet("/HomeServlet")
public class HomeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HomeServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//将浏览器的任务接收,发给业务逻辑层处理
IStudentService service=new StudentServiceImp();
List<Map<String, Object>> oList=service.getStudents();
//将从数据库中查询出来的数据存储至request
request.setAttribute("students", oList);
//请求转发跳转页面
request.getRequestDispatcher("index.jsp").forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
剩下的项目完整代码在下面。
package com.DengLu.And.Zhu.Ce;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class ServlectDengLuLogic
*/
@WebServlet("/ServlectDengLuLogic")
public class ServlectDengLuLogic extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ServlectDengLuLogic() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/**
* do--post
*/
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
ServletContext sc=getServletContext();
//获取web.xml文件中的镜头数据
String a=sc.getInitParameter("QQ");
String b=sc.getInitParameter("PSD");
String c=sc.getInitParameter("USER");
System.out.println(a+"@@@@@@@@"+b);
response.getWriter().append("ServletB获得静态数据用来访问web.xml"+a);
String aa=request.getParameter("qq");
String bb=request.getParameter("psd");
String cc=request.getParameter("user");
//不区分大小写equalsIgnoreCase(aa)
if(a.equalsIgnoreCase(aa)&&b.equalsIgnoreCase(bb)&&c.equalsIgnoreCase(cc)) {
//重定向跳转页面
System.out.println("登录成功跳转到2021登录成功");
response.sendRedirect("HomeServlet");
/* response.setHeader("refresh","60;URL=Register.jsp"); */
}else {
System.out.println("登录失败五秒后返回Register.jsp");
/* response.sendRedirect("Register.jsp"); */
response.setHeader("refresh","3;URL=Register.jsp");
}
}
}
package com.DengLu.And.Zhu.Ce;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class ServlectDengLuLose
*/
@WebServlet("/DengLuChengGong")
public class ServlectDengLuLose extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ServlectDengLuLose() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter pw = response.getWriter();
pw.append("60秒后回到index.jsp");
response.setHeader("refresh","60;URL=index.jsp");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
package com.DengLu.And.Zhu.Ce;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class ServlectDengLuLogic
*/
@WebServlet("/ServlectZhuCe")
public class ServlectZhuCe extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ServlectZhuCe() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/**
* do--post
*/
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
ServletContext sc=getServletContext();
//获取web.xml文件中的镜头数据
String a=sc.getInitParameter("USER");
String b=sc.getInitParameter("QQ");
String c=sc.getInitParameter("PSD");
String d=sc.getInitParameter("SJ");
String e=sc.getInitParameter("HOME");
System.out.println(a+"@@@"+b+"@@@"+c+"@@@"+d+"@@@"+e);
response.getWriter().append("<h1>ServlectZhuCe获得静态数据用来访问web.xml</h1>");
String aa=request.getParameter("user");
String bb=request.getParameter("qq");
String cc=request.getParameter("psd");
String dd=request.getParameter("sj");
String ee=request.getParameter("home");
//不区分大小写equalsIgnoreCase(aa)
if(a.equalsIgnoreCase(aa)&&b.equalsIgnoreCase(bb)&&c.equalsIgnoreCase(cc)&&d.equalsIgnoreCase(dd)&&e.equalsIgnoreCase(ee)) {
//重定向跳转页面
System.out.println("注册成功跳转到2021登录成功");
response.sendRedirect("Login.jsp");
/* response.setHeader("refresh","60;URL=Register.jsp"); */
}else {
System.out.println("注册失败五秒后返回Register.jsp");
/* response.sendRedirect("Register.jsp"); */
response.setHeader("refresh","8;URL=ZhuCeLose");
}
}
}
package com.DengLu.And.Zhu.Ce;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class ServlectDengLuLose
*/
@WebServlet("/ZhuCeLose")
public class ZhuCeLose extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ZhuCeLose() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
response.setHeader("refresh", "5");
//设置要求浏览器
/* response.sendRedirect("Servlet1"); */
int i=(int)(Math.random()*900000+100000);
int a=(int)(Math.random()*9000+1000);
int c=(int)(Math.random()*900+100);
System.out.println("@@@@"+(new Random().nextInt(900000)+100000));
/*
* 设置随机
*/
System.out.println(new Random().nextInt(100));
System.out.println(Math.random());
PrintWriter pw =response.getWriter();
pw.print("你的支付宝到账1000万元,需要的码号为:<h1 style='color:red ;background-color:green'>"+i+"</h1>,打死也不说 \"<hr>\";");
pw.print("你的QQ到账1000万元,需要的码号为:<h2 style='color:red ;background-color:green'>"+c+"</h2>,打死也不说 \"<hr>\";");
pw.print("你的微信到账1000万元,需要的码号为:<span style='color:green'>"+a+"</span>,打死也不说");
pw.print("你的手机支付宝到账1000万<span style='color :red'>"+i+"</span>");
pw.append("<style>");
pw.append(" *{\r\n" +
" margin: 0px;\r\n" +
" padding: 0px;\r\n" +
" background: white;\r\n" +
" font-size: 30px;\r\n" +
" font-weight: bold;\r\n" +
" text-shadow: 1px 1px 1px red;\r\n" +
"\r\n" +
" }");
pw.append("</style>");
pw.append("<h1 align ='center'>2021你年垮2022年QQ登陆失败的界面</h1>");
pw.append("注册界面失败请重新注册");
response.setHeader("refresh","5;URL=Register.jsp");
pw.append("<h2 align ='center'><a href='Register.jsp'>点击这里返回注册界面进行重新注册</a></h2>");
pw.append("如果用户一分钟后没有任何操作则在60秒后调到index.jsp文件");
response.setHeader("refresh","30;URL=index.jsp");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
package com.Filter;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class MyFilter4 implements Filter{
public MyFilter4() {
// TODO Auto-generated constructor
System.out.println("我创建了第一个MyFilter过滤器");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
System.out.println("我是myfilter开始拦截请求地址哦哦");
}
@Override
public void init(FilterConfig config) throws ServletException {
// TODO Auto-generated method stub
System.out.println("FilterConfig用来加载初始化数据");
}
@Override
public void destroy() {
System.out.println("Filter所有方法运行完毕后销毁过滤器");
}
}
package com.Listener;
/**
* 第三类接口
*/
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
public class Listener implements HttpSessionBindingListener {
private int id;
private String username;
private String password;
public Listener() {
// TODO Auto-generated constructor stub
}
public Listener(int id, String username, String password) {
super();
this.id = id;
this.username = username;
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "Listener [id=" + id + ", username=" + username + ", password=" + password + ", getId()=" + getId()
+ ", getUsername()=" + getUsername() + ", getPassword()=" + getPassword() + ", getClass()=" + getClass()
+ ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]";
}
@Override
public void valueBound(HttpSessionBindingEvent event) {
// TODO Auto-generated method stub
System.out.println("HttpSession 与 Listener绑定");
HttpSessionBindingListener.super.valueBound(event);
}
@Override
public void valueUnbound(HttpSessionBindingEvent event) {
// TODO Auto-generated method stub
System.out.println("HttpSession 与 Listener解绑绑");
HttpSessionBindingListener.super.valueUnbound(event);
}
}
package com.Servlect;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class HomeServlect2
*/
@WebServlet("/HomeServlect2")
public class HomeServlect2 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HomeServlect2() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
PrintWriter pw =response.getWriter();
pw.append("<h1 style='color:red'>登录成功</h1>");
pw.append("<h2>本案例运用的对象\r\n" +
"<hr>\r\n" +
"ServletConfig:对象获得静态数据\r\n" +
"<hr>\r\n" +
"ServletContext对象:获取共享静态数据,获取共享动态数据,获取共享文件数据.\r\n" +
"<hr>\r\n" +
"HttpServletResponse 对象HttpServlet调用HttpResponse的有关方法,生成响应数据\r\n" +
"<hr>\r\n" +
"HttpServletRequest对象:HttpServlet调用HttpResponse的有关方法,生成响应数据,用于服务器上接收浏览器发送过来的数据信息\r\n" +
"<hr>\r\n" +
"Cookie对象,对象Session对象。程序把每个用户的数据以Cookie/Session的形式写给用户各自的浏览器。\r\n" +
"<hr>\r\n" +
"Filter:过滤器,阻止非法网站的访问。\r\n" +
"<hr>\r\n" +
"Listener:\r\n" +
"实现了特定接口的类为监听器,用来监听另一个Java类的方法调用或者属性改变;** 当被监听的对象发生了方法调用或者属性改变后,\r\n" +
"监听器的对应方法就会立即执行.\r\n" +
"<hr>\r\n" +
"九大内置对象的核心表格\r\n" +
"<hr>\r\n" +
"out JspWriter 将文本信息输出浏览器\r\n" +
"<hr>\r\n" +
"request HttpServletRequest 获得浏览器发送来的数据\r\n" +
"<hr>\r\n" +
"respone HttpServletRequest 回复浏览器请求\r\n" +
"<hr>\r\n" +
"seesion HttpSeesion 在不换浏览器放信息\r\n" +
"<hr> \r\n" +
"exception Throwable 异常报错\r\n" +
"<hr>\r\n" +
"page Servlect(this) jsp翻译出来类的对象\r\n" +
"<hr>\r\n" +
"config ServlectConfig 静态数据\r\n" +
"<hr>\r\n" +
"application ServlectContext 共享数据\r\n" +
"<hr>\r\n" +
"pageContext PageContextjsp 管理者引出对象\r\n" +
"<hr>\r\n" +
"seesion 浏览器不切\r\n" +
"application 服务器不关闭\r\n" +
"request:请求转发跳转页面的情况,只能两个页面共享数据\r\n" +
"pageContext:该对象中只能页面自己用\r\n" +
"才能用setAttribute的方法\r\n" +
"将四作用域排序\r\n" +
"pageContext request seesion application \r\n" +
"</h2>");
pw.append("<h1><a href='index.jsp'>返回主界面</a></h1>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
package com.Servlect;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
/**
* Servlet Filter implementation class MyFilter1
*/
//你要阻止Servlect2
@WebFilter("/Servlect2")
public class MyFilter1 implements Filter {
/**
* Default constructor.
*/
public MyFilter1() {
// TODO Auto-generated constructor stub
System.out.println("构造方法");
}
/**
* @see Filter#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
System.out.println("销毁数据");
}
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
System.out.println("我是myfilter1开始拦截请求地址哦哦");
//实施访问
chain.doFilter(request, response);
}
/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
System.out.println("加载数据");
}
}
package com.Servlect;
/**
* 这一个类让我们去了解Servlect的周期
*/
import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class ServlectOne implements Servlet{
public ServlectOne() {
// TODO Auto-generated constructor stub
System.out.println("@1 Servlec方法的构造方法");
}
@Override
public void destroy() {
System.out.println("@2 Servlect方法的销毁");
}
@Override
public ServletConfig getServletConfig() {
// TODO Auto-generated method stub
System.out.println("@ 3Servlect方法加载静态数据");
return null;
}
@Override
public String getServletInfo() {
// TODO Auto-generated method stub
System.out.println("@ 4 Servlect的getServletInfo方法");
return null;
}
@Override
public void init(ServletConfig config) throws ServletException {
// 获取静态数据的对象
String a=config.getInitParameter("SFZ");
System.out.println(a);
System.out.println("@5 Servlecto的init方法");
System.out.println("获取静态数据的对象config");
//动态数据的获取
}
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("@5 Servlecto的servlect方法");
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
*{
text-align: center;
align-content: center;
margin: 30px;
font-size: 30px;
font-weight: 700;
font-family: "微软雅黑";
padding: 2px;
color: red;
background: linear-gradient(to right,red,pink,blue);
}
article{
}
</style>
<title>登录页面</title>
</head>
<body>
<article>
<h1>欢迎来到2021年个人学生信息管理登录界面</h1>
<form action="HomeServlet" method="post">
用户名:<input type="text" name="user" id="text" maxlength="8"><br>
QQ号:<input type='text' name='qq'><br>
密码:<input type='password' name='psd'><br>
<input type='checkbox' value='flase' checked='checked' name='ispsd'>记住密码
<input type='checkbox' value='true' name='islogin'>自动登录<br>
<input type='submit' value='登录'><br>
</form>
</article>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
* {
margin: 0;
padding: 0;
background: white;
background: linear-gradient(to right,red,pink,blue);
}
li {
list-style: none;
}
left {
width: 480px;
float: left;
}
.header {
width: 1040px;
height: 100px;
float: right;
}
.top {
float: right;
}
.main {
width: 500px;
margin: 0 auto;
}
.one h1 {
font-size: 46px;
font-weight: 400;
margin-bottom: 20px;
}
.two {
font-size: 20px;
color: #333333;
margin-bottom: 64px;
float: left;
}
.there {
float: right;
margin-bottom: 64px;
}
.there a {
font-size: 28px;
text-decoration: none;
color: #359eff;
}
.there a:hover {
color: #094683;
}
.input-outer input {
height: 50px;
width: 438px;
margin-bottom: 40px;
border-radius: 10px;
border: 1px solid #c1c1c1;
color: #c1c1c1;
font-size: 20px;
}
.input-outer span,
.input-phone span {
font-size: 25px;
text-align: center;
line-height: 50px;
color: #333333;
}
.input-type select {
margin: auto;
height: 50px;
border-radius: 10px;
border: 1px solid #c1c1c1;
font-size: 20px;
float: left;
}
.input-phone input {
height: 50px;
width: 268px;
border-radius: 10px;
border: 1px solid #c1c1c1;
font-size: 20px;
margin-left: 20px;
}
.input-qq input {
height: 50px;
width: 268px;
border-radius: 10px;
border: 1px solid #c1c1c1;
font-size: 20px;
margin-left: 20px;
}
.input-home input {
height: 50px;
width: 260px;
border-radius: 10px;
border: 1px solid #c1c1c1;
font-size: 20px;
margin-left: 20px;
}
.input-sex input{
height: 50px;
width: 268px;
border-radius: 10px;
border: 1px solid #c1c1c1;
font-size: 20px;
margin-left: 20px;
}
.six p {
color: #c1c1c1;
font-size: 14px;
}
.sub input {
align-content: center;
text-align: center;
height: 50px;
width: 440px;
margin: 40px 0;
font-size: 20px;
color: #ffffff;
background-color: #3588ff;
border: 1px solid #c1c1c1;
border-radius: 10px;
}
.type-radio span {
align-content: center;
text-align: center;
font-size: 14px;
color: #c1c1c1;
}
.footer {
align-content: center;
text-align: center;
margin: 40px 0;
text-align: center;
color: #c1c1c1;
}
h1{
/* text-shadow: 5px 5px 5px red; */
color: red;
}
</style>
<title>注册页面</title>
</head>
<body>
<h1 style="background: aquamarine; color: red; font-weight: 900; text-align: center;">欢迎来到2021年个人学生注册界面</h1>
<article style="text-align: center; align-content: center; text-align: center;">
<form action="ServlectZhuCe" method="post">
<div class="input-outer">
<h1>用户名:</h1><br><input type="text" name="user" id="text" maxlength="8">
</div>
<div class="input-sex">
<h2> 输入性别</h2>
<h2>男:</h2><input type="radio" name="sex" id="" value="1" checked="checked"/>
<h2>女:</h2><input type="radio" name="sex" id="" value="0" checked="checked" />
</div>
<div class="input-qq">
<h1>QQ号:</h1><br><input type="text" name="qq" maxlength="11" minlength="11">
</div>
<div class="input-outer">
<h1>密码 :</h1><br><input type="password" name="psd" id="password" maxlength="16">
</div>
<div class="input-phone">
<h1>手机号:</h1><br><input type="text" name="sj" maxlength="11" minlength="11" >
</div>
<div class="input-home">
<h1>家庭地址:</h1><br><input type="text" name="home" maxlength="11" minlength="11" >
</div>
<div class="six">
<p>可通过手机号找回密码</p>
</div>
</div>
<div class="sub">
<input type="submit" value="立即注册">
</div>
</form>
</article>
<div class="type-radio">
<input type="radio" checked><span style="text-align: center;">同意开通QQ空间</span>
<br>
<input type="radio" checked><span style="text-align: center;">我已阅读并同意相关服务条款和隐私政策开始进行登录QQ页面</span>
</div>
<div>
<footer>
<h1>这是QQ的注册页面</h1>
</footer>
</div>
</div>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
*{
background: linear-gradient(to right,red,pink,blue);
}
</style>
</head>
<body>
<h1 style="background: black; color: red; text-align: center;">欢迎来到学生信息管理注册登录界面</h1>
<a href="Register.jsp"><h1>点击这里进行学生信息注册页面</h1></a>
<h3 style="color:white; background: black;">
MVC全名是Model View Controller,<br>
是
@@1模型(model)<br>
@@2-视图(view)<br>
@@3-控制器(controller)的缩写,<br>
一种软件设计典范,<br>
用一种业务逻辑、数据、界面显示分离的方法组织代码,<br>
将业务逻辑聚集到一个部件里面,在改进和个性化定制界面及用户交互的同时,<br>
不需要重新编写业务逻辑。<br>
MVC被独特的发展起来用于映射传统<br>
的输入、处理和输出功能在一个逻辑<br>
的图形化用户界面的结构中。<br>
</h3>
</body>
</html>
这是整个项目的代码。
这下面的运行图自己思考。
?
?
|