课堂作业一(登陆页面的设计)

it2022-05-05  70

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

       1.需要java的基础。

  2.需要一项有关界面设计的语言基础(Html)。

  3连接数据库的方法。

二.课堂测试的源程序代码。

    

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() { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String user = "sa"; String password = "123456"; String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=jaovo_msg"; Connection connection = null; try {connection 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(); } }}

 

 

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() { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String user = "sa"; String password = "123456"; String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=jaovo_msg"; Connection connection = null; try {connection 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(); } }}

 

<%@page import="com.jaovo.msg.Util.UserException"%><%@page import="com.jaovo.msg.dao.UserDaoImpl"%><%@page import="com.jaovo.msg.model.User"%><%@ 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="login.jsp"></jsp:forward><% }%><% User user = new User(); user.setUsername(username); user.setPassword(password);

UserDaoImpl userDao = new UserDaoImpl(); try { if (userDao.checkuser(user)) {%><jsp:forward page="success.jsp"></jsp:forward> <% } else { request.setAttribute("error", "用户名/密码有误");%>

<jsp:forward page="login.jsp"></jsp:forward><% } } catch (UserException e) {%><h2 style="color: red; font-size: 50px"> 发生错误 : <%=e.getMessage()%></h2><% }%></html>

四.说明课堂测试未按时完成的原因。

课下练习时间少,java基础太差,未能及时预习。

 

转载于:https://www.cnblogs.com/877612838zzx/p/7886535.html


最新回复(0)