软件工程概论(课堂作业01)

一,网站系统开发需要掌握的技术

①首先要安装与配置jdk环境变量

这个在百度上都有,相信大家都可以找得到。这里给一个网址https://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html在这里提醒一句一定要细心的配置变量,因为有时候你配好了在命令行中运行java -version不出错,但是运行程序是会出错。

②然后是编程工具eclipse

从eclipse官网下载适合自己电脑的eclipseEE,安装到电脑上。

③之后是MySQL数据库

安装设置好账户密码。

④最后安装Navicat Premium程序,这个是可以连接并查看一些常见数据库里的文件。

点击file->new->Dynamic Web Project到如下界面

点击New Runtime

选择8.0然后点next

点击browse,选择自己安装的Tomact的位置。

输入创建项目名称,点两次next

勾选选项

 点finish之后是导入jar包

 之后就是写java文件以及jsp文件了。

 二,本次课堂测试的源程序代码

student.java代码如下:

package HaHa;

public class Stuent {
    private String username;
    private String password;
    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;
    }
    
}

studentDao.java代码如下:

package HaHa;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import sun.security.util.Password;
public class StudentDao {
    public boolean denglu(Stuent stuent) {
        Connection connection = DBUtil.getConnection();
        String sql = "select count(*) from t_student where username = ? and password=?";
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        int i=0;
        try {
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,stuent.getUsername());
            preparedStatement.setString(2,stuent.getPassword());
            //接收结果集
            resultSet = preparedStatement.executeQuery();
            //遍历结果集
            while(resultSet.next()) {
                if (resultSet.getInt(1)>0) 
                {
                    i=1;
                }
            }
        }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally {
                //关闭资源
                DBUtil.close(resultSet);
                DBUtil.close(preparedStatement);
                DBUtil.close(connection);
            }
        if(i==1)
        {
            return true;
        }
        else {
            return false;
        }
}
}

DBUtil.java代码如下:

package HaHa;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
    public  static  Connection getConnection() {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String user = "root";
        String password = "root";
        String url = "jdbc:mysql://localhost:3306/student";
        Connection connection = null;
        try {
             connection = DriverManager.getConnection(url,user,password);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return connection;
    }
    
    public static void close(Connection connection ) {
        try {
            if (connection != null) {
                connection.close();
            }
            
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public static void close(PreparedStatement preparedStatement ) {
        try {
            if (preparedStatement != null) {
                preparedStatement.close();
            }
            
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public static void close(ResultSet resultSet ) {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
            
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

denglu.jsp代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生登录</title>
</head>
<body>
   <%=request.getAttribute("error") %>
   <form action ="way.jsp" method ="get">
   <table align="center" border="1" width="500">
        <tr>
          <td>用户名称:</td>
          <td>
             <input type="text" name="username"/>
          </td>
        </tr>
        <tr>
          <td>用户密码:</td>
          <td>
             <input type="password" name="password"/>
          </td>
        </tr>
        <tr align="center">
                <td colspan="2">
                    <input type="submit" value="登录" />
                </td>
            </tr>
            </table>
            </form>
</body>
</html>

way.jsp代码如下:

<%@page import="HaHa.StudentDao"%>
<%@page import="HaHa.Stuent"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
String username =request.getParameter("username");
String password =request.getParameter("password");
if(username==null||"".equals(username.trim())){
       request.setAttribute("error", "用户名不能为空!");
       %>
       <jsp:forward page="denglu.jsp"></jsp:forward>
    <%
}
Stuent stuent=new Stuent();
stuent.setUsername(username);
stuent.setPassword(password);
StudentDao studentDao=new StudentDao();
if(studentDao.denglu(stuent))
{
     %>
       <jsp:forward page="success.jsp"></jsp:forward>
    <%
}
else
{
     %>
       <jsp:forward page="file.jsp"></jsp:forward>
    <%
}
%>

</html>

success.jspp代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
 用户登录成功!!<br>
    <a href="denglu.jsp">继续登录</a><br>
</body>
</html>

file.jap代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
 用户登录失败!!<br>
    <a href="denglu.jsp">继续登录</a><br>
</body>
</html>

三,结果截图

这是我在数据库中创建的一些账户,如上图所示。

运行如下:

点击继续登录

输入错误的账号密码如下:

 

四,课堂测试未按时完成的原因

  由于自己的懒惰,在经过周六的学习之后没有仔细的分析,导致一些知识还是不明白,以前也没接触过这类程序,写起来没有思路只能照抄。自己的自主学习能力还是太低。

五,列出你对这门课的希望和自己的目标,并具体列出你计划每周花多少时间在这门课上

 我发现这门课还是很有趣的,在经过努力后看到自己的成果,感觉还是很开心的,虽然过程十分艰辛。我希望自己在学完这门课后能够自己独立完成一个小软件的开发,自我学习

HTML的知识。因此除了上课的学习外我还要拿出大部分课外时间来学习他。

原文地址:https://www.cnblogs.com/chch157/p/7886699.html