作业5.4

没做完,后续一步不会了,不哈意思。什么时候完全做出来什么时候更新。

保存草稿变成提交了,实际上我并没有做完,不过我到现在依旧可以继续编辑继续更改就行了,撤回回不来变成直播赶作业了。

 


 

1.先完成一部分页面装饰。

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CAPO.Login</title>
<style type="text/css">
.one{ font: normal 18px/30px "微软黑体"}
.two{ font: normal 18px/30px "Wingdings"}
.text{
background:#839080;
border:1px #839080;
}

.loginbox{
width:500px;
height:250px;
">235,240,232,0.7);
border-radius:5px;
margin:0 auto;
padding:180px 300px 180px 300px;
}

.Abutton{
margin-top:20px;
width:190px;
height:30px;
color:#f9f6e9;
font-class:one;
border:0;
background:#5f695d ;
border-radius:10px;

</style>
</head>

<body background="Aimage/hana.jpg" >
<%
String username = (String) session.getAttribute("username");
if (username == null){
username = "";
}
%>
<form action="./loginServlet" method="post">
<br>
<br>
<div class="loginbox" align="center">
<div align="center">
<hr color="#5f695d" size=1px>
<hr color="#5f695d" size=1px width=200px>
<h2><font color="#5f695d" class="one"> 登录 | LOGIN PAGE</font></h2>
<input type="text" name="username" style="width:200px ; height:25px; color:#5f695d"
placeholder=" 账号 Username"/>
<br/>
<br/>
<input type="text" name="password" style="width:200px ; height:25px; color:#5f695d "
placeholder=" 密码 Password"/>
<br/>
<a href="#" target="_blank" class="one">
<font size=2px color="#839080" > 忘记密码? </font>
</a>
<br>
<input type="submit" class="Abutton" name="submit" value="登 录" />
</div>
</div>
</form>

</body>


</html>

 


 

随便放进去最近的摄影当成背景.........不过注意一下盒子模型吧。style="text-decoration:none"可以用这个取消下划线

以及

line-height:设置行间距,放在盒子模型里使用设置文本间距还是不错的

.{

font-size:10px;

line-height:10px;

//line-height:1em;

//line-height:150%;

}

三种设置方式就是了,像素px,相对值em,百分比%

空白符:white-space{  nomal 常规文本空格,空行无效,满行后自动换行。

                pre  预格式化,按照规定格式保留空格以及换行形式。

                nowrap空行空格无效,除非遇到<br/>标签才会换行改变。 

字间距:word-spacing用于规定英文单词之间的字间距,对于中文字符没有用,所以这个用来准备储存诗文很方便吧。

 

设置文本框内输入字体的颜色:input type="text" name=" 给个名字呗" size="20px" style="color: #喜欢的任意色号"

 

 

 


 2.准备了数据库的前提

create table list(
ID char(8) not null primary key,
Password char(8) not null
);
select * from loginlist.list;

 插入,更改数据的语句

insert into list set ID='CAPO',Password='123456';
注意主键是要求唯一的,是不会允许出现重复数据的
insert into 表名 ( 字段名1 ,字段名2 ) value ( ‘赋值1’ ,‘赋值2’ );
如果不定义值而且当前字段可以为null就默认变成null.

可以使用replace来替换数据。
插入多条数据时,数据之间逗号间隔。

 


 3.连接数据库的方法

package MysqlConnect;
import java.sql.*;

public class AM {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/loginlist","root","capo737");
System.out.println("连接成功!??");
System.out.println(connect);
Statement statement =connect.createStatement();



//看见没,从这开始的哦!指指下面
String sql = "select * from list;";
ResultSet rs = statement.executeQuery(sql);
while (rs.next()) {
System.out.println(rs.getString("ID"));
System.out.println(rs.getString("Password"));
}
statement.close();
connect.close();

}
}
结果是可以获取到数据的。这里是没有问题的。
(。・∀・)是的,这里是没问题的。也只是到这里了。

 


 

4.把这些东西组装起来(对不起,不会了)

package OneServlet;
import java.io.IOException;
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 javax.servlet.http.HttpSession;


@WebServlet("/loginServlet")
public class loginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);

}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String username =request.getParameter("username");
String password =request.getParameter("password");
System.out.println("用户名 :"+username);
System.out.println("用户密码"+ password);
System.out.println(username +";"+ password);
//不知道你在说什么,如果你说是固定的话,那么下面是否能够符合你的意见

if (username.equalsIgnoreCase(username)&&password.equals(password)) {
//此处为登陆状况:成功
HttpSession session = request.getSession();
System.out.println(session.isNew()+":"+session.getId()+":"+session.getCreationTime()
+":"
+session.getLastAccessedTime()+":"+session.getMaxInactiveInterval());
session.setAttribute("username", username); // 向 HttpSession 域中保存用户名
response.sendRedirect("./welcome.jsp");

} else {
response.getWriter().print("用户名或密码错误!");
}
}
}


这都是之前写的,密码判断什么的....和数据库内数据对比判断不会(摊手)
不好意思,可能我就是没有天分吧。
什么都不会也做不出来什么。

 

posted @ 2022-05-07 14:22  小石榴单推人  阅读(47)  评论(0)    收藏  举报