《云博客》-------------version2.0(封笔)

最后一次写这个项目了,连续写了几天,想吐,不干了。

本次版本说是加一个拦截器,但是需要session 的存储,太麻烦。不干了,就加一个验证码登录,还有布局的更正。

《云博客》-------------version2.0(封笔)_第1张图片

look,为了防止刷机,所以连夜加一个验证码。每一次刷新页面,就可以刷新验证码。其实按道理说每点击一下就刷新验证码。 也算一个需要改进的地方,但是罢工了不干了,雷晕了。

《云博客》-------------version2.0(封笔)_第2张图片

什么信息都不输入的话,校验信息提示失败。

《云博客》-------------version2.0(封笔)_第3张图片

 《云博客》-------------version2.0(封笔)_第4张图片

注册成功了。

接下来可以进行登录,,

点击超链接,进行登陆界面。

《云博客》-------------version2.0(封笔)_第5张图片 

平台的主界面:

 剩下的和1的version差不多,没有太大的差别,可以参考一下。

点击链接,可以查看1的版本;

链接

上代码:

本代码部分大部分是实现的前后端分离,也有少许部分尚待处理。但是不做了。累;

Servlet01.java

package servlets;

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 java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;

@WebServlet("/s01")
public class Servlet01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String id = request.getParameter("delettext");

        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";
            String un = "root";         //MySql用户名
            String pa = "cjd";  //MySql密码

            Connection con = DriverManager.getConnection(url, un, pa);
            Statement st = con.createStatement();

            System.out.println("delete Successful!");
            String sql = "DELETE FROM we WHERE class =?";
            //   pst = con.prepareStatement(sql);
            PreparedStatement pstmt = con.prepareStatement(sql);
            pstmt.setString(1, id);
            int flag = pstmt.executeUpdate();
            PrintWriter out = response.getWriter();
            if (flag > 0) {
                out.write("删除成功!");
                out.write("返回首页 ");
            } else {
                out.write("删除失败!");
                out.write("返回首页 ");
            }
            con.close();
            st.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Servlet02.java

package servlets;

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 java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;

@WebServlet("/s02")
public class Servlet02 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");

        request.setCharacterEncoding("UTF-8");
        String id = request.getParameter("delettext1");

        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";
            String un = "root";         //MySql用户名
            String pa = "cjd";  //MySql密码

            Connection con = DriverManager.getConnection(url, un, pa);
            Statement st = con.createStatement();
            // PreparedStatement pst = null;
            System.out.println("delete Successful!");
            String sql = "DELETE FROM we WHERE place =?";
            //   pst = con.prepareStatement(sql);
            PreparedStatement pstmt = con.prepareStatement(sql);
            pstmt.setString(1, id);
            int flag = pstmt.executeUpdate();
            PrintWriter out = response.getWriter();
            if (flag > 0) {
                out.println("删除成功!");
                out.print("返回首页 ");
            } else {
                out.println("删除失败!");
                out.print("返回首页 ");
            }
            con.close();
            st.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}

Servlet03.java

package servlets;

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 java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;

@WebServlet("/s03")
public class Servlet03 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        //获取用户输入信息
        request.setCharacterEncoding("utf-8");
        //  response.setHeader (" content - type ","text/ html ; charset = UTF -8");
//    response.setHeader("concent-type,text/html;charset=UTF-8");
        // response.setCharacterEncoding (" UTF -8"");
        response.setCharacterEncoding("UTF-8");
        String username = request.getParameter("username");
        String userpwd = request.getParameter("userpwd");
        Connection conn = null;
        Statement stmt = null;
        try {
            //连接驱动
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        //建立数据库连接
        String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";
        //数据库账号
        String uname = "root";
        //数据库密码
        String upwd = "cjd";

        try {
            conn = DriverManager.getConnection(url, uname, upwd);
            //创建发射器
            stmt = conn.createStatement();
            //创建sql语句
            String sql = "select*from test.yonghu where username='" + username + "' and userpwd='" + userpwd + "'";
            //发送sql语句并接收结果
            ResultSet rs = stmt.executeQuery(sql);
            if (rs.next()) {
                out.write("登陆成功");
                response.sendRedirect("testform01.jsp");
            } else {
                out.write("登陆失败");
                out.write("返回注册 ");
            }
            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}

Servlet04.java

package servlets;

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;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

@WebServlet("/s04")
public class Servlet04 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType( "text/html; charset=UTF-8");
        PrintWriter out = response.getWriter();
        //获取用户输入信息
   //     request.setCharacterEncoding("utf-8");
        String username=request.getParameter("username");
        String userpwd=request.getParameter("userpwd");
        String cuserpwd=request.getParameter("cuserpwd");
        String code = request.getParameter("code");
        //获取session中的验证码
        HttpSession session = request.getSession();
        String randStr = (String)session.getAttribute("randStr");
     //   response.setCharacterEncoding("UTF-8");
        //判断两次密码是否相同
        if (cuserpwd.equals(userpwd) && code.equals(randStr) && username!=null&& !username.equals("") &&
        userpwd!=null && !userpwd.equals("") && cuserpwd!=null && !cuserpwd.equals("")) {
            Connection conn = null;
            Statement stmt = null;
            try {
                //连接驱动
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            //建立数据库连接
            String url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";;
            //数据库账号
            String user="root";
            //数据库密码
            String upwd="cjd";
            try {
                conn= DriverManager.getConnection(url,user,upwd);
                //创建发射器
                stmt=conn.createStatement();
                //创建sql语句
                String sql="insert into yonghu(username,userpwd) value ('"+username+"','"+userpwd+"')";
                //发送sql语句并接收结果
                int count = stmt.executeUpdate(sql);
                if (count>0){
                    out.write("注册成功");
                    out.write("登录 ");
                }
                else{
                    out.write("验证码或者密码不一致或者账号错误导致注册失败");
                    out.write("返回注册界面 ");
                }
                //关闭资源
                stmt.close();
                conn.close();

            } catch (SQLException e) {
                e.printStackTrace();
            }
        } else {
            out.write("注册失败"+"
"); out.write("
返回注册界面 "); } } }

Servlet05.java

package servlets;

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 java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@WebServlet("/s05")
public class Servlet05 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        String name = request.getParameter("textname");
        String pwd = request.getParameter("u1");
        String place = request.getParameter("place");
        String time = request.getParameter("time1");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
        Date date = null;
        try {
            date = new Date(format.parse(time).getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int num = Integer.parseInt(request.getParameter("classuser"));
        String textname1 = request.getParameter("textname1");

        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";
            String un = "root";         //MySql用户名
            String pa = "cjd";  //MySql密码

            Connection con = DriverManager.getConnection(url, un, pa);
            Statement st = con.createStatement();
//    String sql = "select * from we";
            System.out.println("Connection Successful!");
            String sql = "Insert into we(name,sex,class,topic,rtime,place) values(?,?,?,?,?,?)";
            PreparedStatement pstmt = con.prepareStatement(sql);
            pstmt.setString(1, name);
            pstmt.setString(2, pwd);
            pstmt.setInt(3, num);
            pstmt.setString(4, textname1);
            pstmt.setDate(5,date);
            pstmt.setString(6,place);
            int n = pstmt.executeUpdate();

            if (n == 1) {out.write("数据插入成功!
");} else {out.write("数据插入失败!"); } out.write("
返回首页 "); con.close(); st.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } }

Servlet06.java

package servlets;

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 java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@WebServlet("/s06")
public class Servlet06 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        String name1 = request.getParameter("updatetext");
        String sex1 = request.getParameter("updatesex");
        int num1 = Integer.parseInt(request.getParameter("updateclass"));
        String topic1 = request.getParameter("updatetopic");
        String place = request.getParameter("place1");
        String time = request.getParameter("date1");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
        try {
            Date date = new Date(format.parse(time).getTime());


            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";
            String un = "root";         //MySql用户名
            String pa = "cjd";  //MySql密码

            Connection con = DriverManager.getConnection(url, un, pa);
            Statement st = con.createStatement();

            System.out.println("update Successful!");
//    String sql ="update we set sex=?,class=?,topic=? where name=?";
            String sql = "update we set sex=?,name=?,topic=?,rtime=?,place=? where class=?";
            // pst = con.prepareStatement(sql);
            PreparedStatement pstmt = con.prepareStatement(sql);
            pstmt.setString(1, sex1);
            pstmt.setInt(6, num1);
            pstmt.setString(3, topic1);
            pstmt.setString(2, name1);
            pstmt.setDate(4, date);
            pstmt.setString(5, place);


            int flag = pstmt.executeUpdate();
            if (flag > 0) {
                out.write("修改成功!");
                out.write("返回主页面 ");
            } else {
                out.write("修改失败");
                out.write("返回主页面  ");
            }
            con.close();
            st.close();
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}

------------------------------------------------------------------------------------------------------------------------------

后端部分完成。上前端!

delete1.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java"
         pageEncoding="UTF-8"
         import="java.sql.*"
%>


    delete table here


个人云博客在线平台







<% request.setCharacterEncoding("UTF-8"); String id = request.getParameter("delettext"); Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8"; String un = "root"; //MySql用户名 String pa = "cjd"; //MySql密码 Connection con = DriverManager.getConnection(url, un, pa); Statement st = con.createStatement(); System.out.println("delete Successful!"); String sql = "DELETE FROM we WHERE class =?"; PreparedStatement pstmt = con.prepareStatement(sql); pstmt.setString(1, id); int flag = pstmt.executeUpdate(); if (flag > 0) { out.println("删除成功!"); out.print("
返回首页 "); } else { out.println("删除失败!"); out.print("返回首页 "); } con.close(); st.close(); %>

有些jsp页面尽管没用,但是带上,方便更好的参照

delete2.jsp

<%--
  Created by IntelliJ IDEA.
  User: ${陈平安}
  Date: 2022/5/30
  Time: 13:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"
         pageEncoding="UTF-8"
         import="java.sql.*"
%>


    Title


个人云博客在线平台







<% request.setCharacterEncoding("UTF-8"); String id = request.getParameter("delettext1"); Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8"; String un = "root"; //MySql用户名 String pa = "cjd"; //MySql密码 Connection con = DriverManager.getConnection(url, un, pa); Statement st = con.createStatement(); // PreparedStatement pst = null; System.out.println("delete Successful!"); String sql = "DELETE FROM we WHERE place =?"; // pst = con.prepareStatement(sql); PreparedStatement pstmt = con.prepareStatement(sql); pstmt.setString(1, id); int flag = pstmt.executeUpdate(); if (flag > 0) { out.println("删除成功!"); out.print("
返回首页 "); } else { out.println("删除失败!"); out.print("返回首页 "); } con.close(); st.close(); %>

delete101.jsp

<%--
  Created by IntelliJ IDEA.
  User: ${陈平安}
  Date: 2022/5/29
  Time: 11:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


个人云博客在线平台







<% request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); %>
输入你要删除的日志序号:


输入你要删除的日志地区:

help.jsp

<%--
  Created by IntelliJ IDEA.
  User: ${陈平安}
  Date: 2022/5/29
  Time: 14:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


敬请期待。。。。。。。。
<% out.print("
返回首页 "); %>

logoin.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    logoin


个人云博客在线平台







用户名:
密码:

logoin_yz.jsp

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    



个人云博客在线平台







<% //获取用户输入信息 request.setCharacterEncoding("utf-8"); // response.setHeader (" content - type ","text/ html ; charset = UTF -8"); // response.setHeader("concent-type,text/html;charset=UTF-8"); // response.setCharacterEncoding (" UTF -8""); response.setCharacterEncoding("UTF-8"); String username=request.getParameter("username"); String userpwd=request.getParameter("userpwd"); // if ((username==null || username.equals("")||(userpwd.equals("")||userpwd==null)) ){ // out.print("登陆失败"); // out.print("
返回注册 "); // } Connection conn = null; Statement stmt = null; try { //连接驱动 Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } //建立数据库连接 String url = "jdbc:mysql://localhost:3306/test"; //数据库账号 String uname="root"; //数据库密码 String upwd="cjd"; try { conn = DriverManager.getConnection(url, uname, upwd); //创建发射器 stmt = conn.createStatement(); //创建sql语句 String sql = "select*from test.yonghu where username='"+username+"' and userpwd='"+userpwd+"'"; //发送sql语句并接收结果 ResultSet rs = stmt.executeQuery(sql); if (rs.next()) { out.print("登陆成功"); response.sendRedirect("testform01.jsp"); } else { out.print("登陆失败"); out.print("返回注册 "); } rs.close(); } catch (SQLException e) { e.printStackTrace(); } %>

registered.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    注册



个人云博客在线平台


输入用户名:
输入密码:
确认密码:
请输入验证码:
<% out.print("已有账号,去登陆"+"
登录 "); %>

Show.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"
         import="java.sql.*"
%>



    
    Insert title here

个人云博客在线平台







<% //star request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); String name5 = request.getParameter("showtext"); Class.forName("com.mysql.jdbc.Driver"); String url ="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8"; String un = "root"; //MySql用户名 String pa = "cjd"; //MySql密码 Connection con = DriverManager.getConnection(url, un, pa); request.setCharacterEncoding("UTF-8"); // Statement st = con.createStatement(); // WHERE name ="+name5; out.print(name5); String sql = "SELECT * FROM we where class =?"; PreparedStatement preparedStatement = con.prepareStatement(sql); preparedStatement.setString(1,name5); ResultSet resultSet = preparedStatement.executeQuery(); resultSet.last(); %>
你要查询的日志数据表中共有 <%=resultSet.getRow()%>条 <% resultSet.beforeFirst(); while (resultSet.next()){ %> <%}%>
记录条数 日志题目 天气 日志序号 日志内容 时间 地区
<%=resultSet.getRow()%> <%=resultSet.getString("name")%> <%=resultSet.getString("sex")%> <%=resultSet.getInt("class")%> <%=resultSet.getString("topic")%> <%=resultSet.getString("rtime")%> <%=resultSet.getString("place")%>
<% if (resultSet!=null){ resultSet.close(); } if (preparedStatement!=null){ preparedStatement.close(); } if (con!=null){ con.close(); } %>
<% out.print(" "+" "+" "+" "+"
返回首页 "); %>

Show01.jsp

<%--
  Created by IntelliJ IDEA.
  User: ${陈平安}
  Date: 2022/5/29
  Time: 11:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


个人云博客在线平台







<% request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); %>
请输入你要查询的日志的序号


请输入你要查询的日志的大概地区(可能无结果)

Show.jsp

<%--
  Created by IntelliJ IDEA.
  User: ${陈平安}
  Date: 2022/5/30
  Time: 13:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"
         pageEncoding="UTF-8"
         import="java.sql.*"
%>


    Title


个人云博客在线平台







<% request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); String name5 = request.getParameter("showtext1"); Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8"; String un = "root"; //MySql用户名 String pa = "cjd"; //MySql密码 Connection con = DriverManager.getConnection(url, un, pa); request.setCharacterEncoding("UTF-8"); out.print(name5); String sql = "SELECT * FROM `we`WHERE place = ?"; PreparedStatement preparedStatement = con.prepareStatement(sql); preparedStatement.setString(1, name5); ResultSet resultSet = preparedStatement.executeQuery(); resultSet.last(); %>
你要查询的日志数据表中共有 <%=resultSet.getRow()%> 条 <% resultSet.beforeFirst(); while (resultSet.next()) { %> <%}%>
记录条数 日志题目 天气 地区 时间 日志序号 日志内容
<%=resultSet.getRow()%> <%=resultSet.getString("name")%> <%=resultSet.getString("sex")%> <%=resultSet.getInt("class")%> <%=resultSet.getString("topic")%> <%=resultSet.getString("rtime")%> <%=resultSet.getString("place")%>
<% if (resultSet != null) { resultSet.close(); } if (preparedStatement != null) { preparedStatement.close(); } if (con != null) { con.close(); } %>
<% out.print(" " + " " + " " + " " + "
返回首页 "); %>

test.jsp

<%@ page language="java"
         pageEncoding="UTF-8"
         import="java.sql.*"
%>
<%@ page import="java.text.SimpleDateFormat" %>



    Insert title here

个人云博客在线平台







<% request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); String name = request.getParameter("textname"); String pwd = request.getParameter("u1"); String place = request.getParameter("place"); String time = request.getParameter("time1"); SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd"); java.sql.Date date = new java.sql.Date(format.parse(time).getTime()); int num = Integer.parseInt(request.getParameter("classuser")); String textname1 = request.getParameter("textname1"); Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8"; String un = "root"; //MySql用户名 String pa = "cjd"; //MySql密码 Connection con = DriverManager.getConnection(url, un, pa); Statement st = con.createStatement(); // String sql = "select * from we"; System.out.println("Connection Successful!"); String sql = "Insert into we(name,sex,class,topic,rtime,place) values(?,?,?,?,?,?)"; PreparedStatement pstmt = con.prepareStatement(sql); pstmt.setString(1, name); pstmt.setString(2, pwd); pstmt.setInt(3, num); pstmt.setString(4, textname1); pstmt.setDate(5,date); pstmt.setString(6,place); int n = pstmt.executeUpdate(); if (n == 1) {%>数据插入成功!
<%} else {%>数据插入失败!
<% } out.print("
返回首页 "); con.close(); st.close(); %>

test01.jsp

<%--
  Created by IntelliJ IDEA.
  User: ${陈平安}
  Date: 2022/5/29
  Time: 11:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


个人云博客在线平台





<% request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); %>
个日志记录
日志标题:
天气:
地点:
时间:
日志内容:

testform01.jsp

<%--
  Created by IntelliJ IDEA.
  User: ${陈平安}
  Date: 2022/5/29
  Time: 11:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


个人云博客在线平台主页面







<% // out.print("返回首页 "); request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); out.println("增加日志 "+" "+" "+" "); out.println("删除日志 "+" "+" "+" "); out.println("浏览日志 "+" "+" "+" "); out.println("修改日志 "+" "+" "+" "); out.println("退出 "+" "+" "+" "); out.println("更多 "+" "+" "); %>

Update1.jsp

<%--
  Created by IntelliJ IDEA.
  User: ${陈平安}
  Date: 2022/4/17
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.sql.*" %>
<%@ page import="java.text.SimpleDateFormat" %>


    update table here


个人云博客在线平台







<% request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); String name1 = request.getParameter("updatetext"); String sex1 = request.getParameter("updatesex"); int num1 = Integer.parseInt(request.getParameter("updateclass")); String topic1 = request.getParameter("updatetopic"); String place = request.getParameter("place1"); String time = request.getParameter("date1"); SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd"); java.sql.Date date = new java.sql.Date(format.parse(time).getTime()); Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8"; String un = "root"; //MySql用户名 String pa = "cjd"; //MySql密码 Connection con = DriverManager.getConnection(url, un, pa); Statement st = con.createStatement(); System.out.println("update Successful!"); // String sql ="update we set sex=?,class=?,topic=? where name=?"; String sql = "update we set sex=?,name=?,topic=?,rtime=?,place=? where class=?"; // pst = con.prepareStatement(sql); PreparedStatement pstmt = con.prepareStatement(sql); pstmt.setString(1, sex1); pstmt.setInt(6, num1); pstmt.setString(3, topic1); pstmt.setString(2, name1); pstmt.setDate(4, date); pstmt.setString(5, place); int flag = pstmt.executeUpdate(); if (flag > 0) { out.println("修改成功!"); out.print("
返回主页面 "); } else { out.println("修改失败"); out.print("返回主页面 "); } con.close(); st.close(); %>

Update101.jsp

<%--
  Created by IntelliJ IDEA.
  User: ${陈平安}
  Date: 2022/5/29
  Time: 11:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


个人云博客在线平台







<% request.setCharacterEncoding("UTF-8"); %>
输入你要修改后的日志标题:
输入你要修改后的日志天气:
输入你要修改后的日志序号:
输入你要修改后的日志时间:
输入你要修改后的日志地区:
输入你要修改后的日志内容:

validate.jsp

<%@ page language="java"
	import="java.awt.*"
	import="java.awt.image.BufferedImage"
	import="java.util.*"
	import="javax.imageio.ImageIO"	
	pageEncoding="utf-8" contentType="text/html;charset=UTF-8"
%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
	response.setHeader("Cache-Control","no-cache");
	// 在内存中创建图象 
	int width = 60, height = 20;
	BufferedImage image = new BufferedImage(width, height,
		BufferedImage.TYPE_INT_RGB);
	//获取画笔
	Graphics g = image.getGraphics();
	//设定背景色 
	g.setColor(new Color(200, 200, 200));
	g.fillRect(0, 0, width, height);
	//取随机产生的验证码(4位数字) 
	Random rnd = new Random();
	int randNum = rnd.nextInt(8999) + 1000;
	String randStr = String.valueOf(randNum);
	//将验证码存入session
	session.setAttribute("randStr", randStr);
	//将验证码显示到图象中 
	g.setColor(Color.black);
	g.setFont(new Font("", Font.PLAIN, 20));
	g.drawString(randStr, 10, 17);
	// 随机产生100个干扰点,使图象中的验证码不易被其他程序探测到 
	for (int i = 0; i < 100; i++){
		int x = rnd.nextInt(width);
		int y = rnd.nextInt(height);
		g.drawOval(x, y, 1, 1);
	}
	// 输出图象到页面 
	ImageIO.write(image, "JPEG", response.getOutputStream());
	out.clear();
	out = pageContext.pushBody();
%>

zc.jsp

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


个人云博客在线平台







<% //获取用户输入信息 request.setCharacterEncoding("utf-8"); String username = request.getParameter("username"); String userpwd = request.getParameter("userpwd"); String cuserpwd = request.getParameter("cuserpwd"); //判断两次密码是否相同 if (cuserpwd.equals(userpwd)) { Connection conn = null; Statement stmt = null; try { //连接驱动 Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } //建立数据库连接 String url = "jdbc:mysql://localhost:3306/test"; //数据库账号 String user = "root"; //数据库密码 String upwd = "cjd"; try { conn = DriverManager.getConnection(url, user, upwd); //创建发射器 stmt = conn.createStatement(); //创建sql语句 String sql = "insert into yonghu(username,userpwd) value ('" + username + "','" + userpwd + "')"; //发送sql语句并接收结果 int count = stmt.executeUpdate(sql); if (count > 0) { out.print("注册成功"); out.print("
登录 "); } else { out.print("注册失败"); out.print("返回注册界面 "); } //关闭资源 stmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } else if (username == null || cuserpwd == null || username.equals("") || cuserpwd.equals("") || userpwd == null || userpwd.equals("")) { out.print("注册失败" + "
"); out.print("
返回注册界面 "); } else { out.print("注册失败" + "
"); out.print("
返回注册界面 "); } %>)

《云博客》-------------version2.0(封笔)_第6张图片

数据库建表;

 《云博客》-------------version2.0(封笔)_第7张图片

 

你可能感兴趣的:(网站开发,java,mysql,数据库)