zoukankan      html  css  js  c++  java
  • 软件工程概论第一节

    1.需要网站系统开发需要掌握的技术;

    1. 至少熟悉一种建站程序。

    2. 对空间和域名的知识有一定的了解。

    3. 有一些美工基础。

    4. 对编程有一些了解。

    5. 代码知识基本的要懂。

    6. css+div会一点。

    7. 简单的网站优化技术。

    8. 熟悉引擎规则。

    2.源程序代码

      1.package com.jaovo.msg.dao;

    //import java.util.List;

    import com.jaovo.msg.model.User;

    public interface ILoginDao {//�ӿ�
        public void add(User user);
        public void delete(String name);
        public void update(User user);
        public void judge(User user);
        /*public User load(String name);
        public User load(String password);
        public List<User> load();*/
    }
      2.package com.jaovo.msg.dao;

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

    import com.jaovo.msg.Util.DBUtil;
    import com.jaovo.msg.Util.UserException;
    import com.jaovo.msg.model.User;

    public class UserDaoImpl implements ILoginDao{

        @Override
        public void add(User user) {
            // TODO Auto-generated method stub
            //��ö���
            Connection connection =DBUtil.getConnection();
            //׼��SQL��䣻
            String sql="select count(*) from User_1 where name=? ";//��ѯ��û��
            //������䴫�����
            PreparedStatement preparedStatement=null;
            ResultSet resultSet=null;
            try {
                 preparedStatement=connection.prepareStatement(sql);
                 preparedStatement.setString(1, user.getName());
                 //���ܽ����
                 resultSet=preparedStatement.executeQuery();
                 //����
                 while(resultSet.next()){//�������
                     if(resultSet.getInt(1)>0){//1Ϊ��һ���ʺ�
                         throw new UserException("�û��Ѵ���");
                     }
                 }//���û�о������ݿ��������
                 sql="insert into User_1(name,password) value(?,?)";
                 preparedStatement=connection.prepareStatement(sql);
                 preparedStatement.setString(1,user.getName());
                 preparedStatement.setString(2,user.getPassword());
                 preparedStatement.executeUpdate();//����
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally{//�ر���Դ�ķ���
                DBUtil.close(resultSet);
                DBUtil.close(preparedStatement);
                DBUtil.close(connection);
                
            }
        }

        @Override
        public void delete(String name) {
            // TODO Auto-generated method stub
            Connection connection =DBUtil.getConnection();
            String sql="delete from User_1 where name=?";
            PreparedStatement preparedStatement=null;
            try {
                preparedStatement=connection.prepareStatement(sql);
                preparedStatement.setString(1,name);
                preparedStatement.executeUpdate();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally{            
                DBUtil.close(preparedStatement);
                DBUtil.close(connection);
            }
            
                    
        }

        @Override
        public void update(User user) {
            // TODO Auto-generated method stub
            Connection connection=DBUtil.getConnection();
            String sql="update User_1 set password=?";
            PreparedStatement preparedStatement=null;
            //ResultSet resuleSet=null;
            try {
                preparedStatement=connection.prepareStatement(sql);
                //preparedStatement.setString(1, user.getName());
                preparedStatement.setString(1, user.getPassword());
                preparedStatement.executeUpdate();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
                    
        }
        @Override
        public void judge(User user){
            Connection connection=DBUtil.getConnection();
            //String sql="select count(*) from User_1 where name=?";
            String sql = "select * from User_1";
            PreparedStatement preparedStatement=null;
            ResultSet resultSet=null;
            int flag = 0;
            try {
                preparedStatement=connection.prepareStatement(sql);
                //preparedStatement.setString(1, user.getName());
                //preparedStatement.setString(2, user.getPassword());
                resultSet=preparedStatement.executeQuery();//结果集
                
                while(resultSet.next()){//�������
                    //1Ϊ��һ���ʺ�
                    
                    String name = resultSet.getString("用户名");
                    String password = resultSet.getString("密码");
                    
                         if(name.equals(user.getName())&&password.equals(user.getPassword())){
                                  System.out.print("登陆成功");
                                  flag = 1;
                                  break;
                         }
                 }
                if(flag!=1)throw new UserException("用户名或密码错误");
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally{//�ر���Դ�ķ���
                DBUtil.close(resultSet);
                DBUtil.close(preparedStatement);
                DBUtil.close(connection);
                
            }
        }
            
    }
      3.package com.jaovo.msg.model;

    public class User {
        private String name;
        private String password;
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }
    }
      4.package com.jaovo.msg.Util;

    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(){
            
            return null;
            
        }*/
        private static final String DRIVER=
                "com.microsoft.sqlserver.jdbc.SQLServerDriver";            //������
        private static final String URL=
                "jdbc:sqlserver://localhost:1433;DatabaseName=jqk;";//URL
        private static final String USER="sa";                    //����
        private static final String PASSWORD="root";            //����
        public static Connection getConnection() {                //�������ݿ�
            Connection connection=null;
            try{
                Class.forName(DRIVER);                            //ע������
                connection=DriverManager.getConnection(URL,USER,PASSWORD);//��������
                }catch(Exception ex) {
                //ex.printStackTrace();
                    System.out.println(ex.getMessage());
                }
            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  prepareStatement){
            try {//
                if(prepareStatement!=null){
                    prepareStatement.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();
            }
        }
    }
      5.package com.jaovo.msg.Util;

    public class UserException extends RuntimeException {

        public UserException() {
            super();
            // TODO Auto-generated constructor stub
        }

        public UserException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
            super(message, cause, enableSuppression, writableStackTrace);
            // TODO Auto-generated constructor stub
        }

        public UserException(String message, Throwable cause) {
            super(message, cause);
            // TODO Auto-generated constructor stub
        }

        public UserException(String message) {
            super(message);
            // TODO Auto-generated constructor stub
        }

        public UserException(Throwable cause) {
            super(cause);
            // TODO Auto-generated constructor stub
        }



    }
      6.<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    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>
      <title>用户登录</title>  
      </head>
      <body>
      <%=request.getAttribute("error") %>
          <form action="add.jsp" method="post">
                  
                  <table align="center" border="1" width="250">
                  
                      <tr>
                          <td>用户名 :</td>
                          <td>
                              <input type="text" name="name" />
                          </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>
      7.<%@page import="com.jaovo.msg.model.User" %>
    <%@page import="com.jaovo.msg.dao.UserDaoImpl" %>
    <%@page import="com.jaovo.msg.Util.UserException"%>
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>

    <%
        String name=request.getParameter("name");
        String password=request.getParameter("password");
        System.out.println(name);
        System.out.println(password);
        if(name==null||"".equals(name.trim())){
        request.setAttribute("error","用户名不能为空!");
        

     %>
    <jsp:forward page="addInput.jsp"></jsp:forward>
     <%
     }
         User user = new User();
        user.setName(name);
        user.setPassword(password);

     UserDaoImpl userDao=new UserDaoImpl();

     userDao.judge(user);
       %>



    </html>

    3.截图

      1.创建数据库,创建表,有用户名,密码两列;

      2.用户名为空

    .

      3.输入正确;

      4.输入错误

    4.未完成原因

      1.对数据库链接不够熟悉,获得SQL语句与web界面基本代码不熟悉;

    5.希望与目标

      希望可以独立完整的开发一个简单的网页版miss系统;

  • 相关阅读:
    【BNUOJ 4358】 左手定则
    【NOIP】关押罪犯
    【数算A】表达式·表达式树·表达式求值
    【POJ1679】The Unique MST
    【数算A】舰队、海域出击!
    【NOI2014】动物园
    【POJ1308】&&【HDU1272】Is It A Tree && 小希的迷宫
    【NOI2002】银河英雄传说
    html5之本地存储localStorage示例
    html5之应用缓存示例
  • 原文地址:https://www.cnblogs.com/liushiqiang123/p/7887200.html
Copyright © 2011-2022 走看看