1. 程式人生 > >軟件工程概論課後作業1

軟件工程概論課後作業1

fresh 課後作業 tran success ins uml header pan ges

1.網站系統開發需要掌握的技術:

JSP、Servlet、JDBC、JavaBean、UML統一建模語言的UML圖、JavaScript、XML、html、css語言。

2.源代碼:

addInut.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>
    <title>用戶添加頁面</title>
</head>
<body>
    <%=request.getAttribute("
error") %> <form action="add.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> <td>用戶昵稱:</td> <td> <input type="text" name="nickname" /> </td> </tr> <tr align="
center"> <td colspan="2"> <input type="submit" value="提交" /> <input type="reset" value="重置" /> </td> </tr> </table> </form> </body> </html>

login1

<%@ 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>

<title>登錄界面</title>
</head>
<body style="background-image:url(‘../image/back.jpg‘);">
   
           
           <%//=request.getAttribute("error") %>
           <center style="color:black ; font-family:宋體;font-size:16px">登錄</center>
    <form action="login2.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>
            <tr align="center">
                <td colspan="2">
                    <input type="submit" value="登錄" />
                    
                    <a href="addInput.jsp">點擊註冊</a><br>
                </td>
            </tr>
        </table>
        <br>
        <center> <%=request.getAttribute("error") %></center>
    </form>

</body>
</html>

login2

<%@page import="com.jaovo.msg.Util.UserException"%>
<%@page import="com.jaovo.msg.dao.UserDaoImpl"%>
<%@page import="com.jaovo.msg.model.User"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="com.jaovo.msg.Util.DBUtil"%>
<%@ 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="login1.jsp"></jsp:forward>
        <%

    }
    
    User user = new User();
    user.setUsername(username);
    
    UserDaoImpl userDao = new UserDaoImpl();
    
    Connection connection=DBUtil.getConnection();
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    
        String sql = "select * from t_user where username = ?";
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, user.getUsername());
        resultSet = preparedStatement.executeQuery();

        
        if(resultSet.next())
        {
     
            if(resultSet.getString("password").equals(password) ){
        
                //response.sendRedirect("loginsuccess.jsp");
                out.print("<script language=‘javaScript‘> alert(‘登陸成功‘);</script>");
                response.setHeader("refresh", "0;url=login.jsp");
            }
            else{
          
                    out.print("<script language=‘javaScript‘> alert(‘密碼錯誤‘);</script>");
                    response.setHeader("refresh", "0;url=login.jsp");
            
            }
        }
        else 
        {
        
             out.print("<script language=‘javaScript‘> alert(‘賬號錯誤——else‘);</script>");
            response.setHeader("refresh", "0;url=login.jsp");
         
        }
%>
    
    
</html>

3.實驗截圖

技術分享圖片

技術分享圖片

4.對這門課的希望和自己的目標:

希望可以好好學習,爭取不掛科

5.每周花多少時間在這門課上:

每天大約兩小時左右

軟件工程概論課後作業1