zoukankan      html  css  js  c++  java
  • 简单java web实现界面开发

    有关javaweb的一个简单的登陆界面开发 这里使用的工具是eclipse、sql 2016、tomcat8

    开发前需要在eclipse中完成tomcat和SQL的连接配置,这里tomcat在web项目运行时会自动的启动,下边介绍开发步骤

    一、web项目的建立

    打开eclipse点解File->New—>Dynamic Web Project

     进入以下界面,输入项目名称

     

    点击next

    再点击next,进入下一界面

    将箭头指向的位置选中,点击finish及完成Web项目的创建

    三、数据库建表

    打开数据库右击数据库新建数据库

    点击新建好的数据库,右击表->新建->表

    在这里输入列名,选择好数据类型

    打开后输入信息

    保存及完成数据库表的建立

    四、数据库连接

    将sqljdbc4.jar文件拖入WEB-INF中

    五、添加JSP文件

    右击WebContent

    Finish完成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=ISO-8859-1">
    <title>Insert title here</title>
    </head> 
    <body>
    
    <center>
    <form action="check.jsp" method="post">//执行check.jsp文件
    用户:<input type="text" name = "username"><br> 密码:<input type="password" name="pass"><br> <input type="submit" value="登陆"> </form> </center> </body> </html>

    运行,可完成界面的创建

    输入一下代码

    <%@ page language="java" import="java.sql.*" 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>
        <%
          String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
          String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=hh";
          String userName="sa";//数据库的登陆账号密码
          String userPwd="g15034014195";
    
        Class.forName(driverName);
        Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
        String sql = "select * from log where [user]=? and [pass]=?";//user pass代表数据库中所创建的列名
    PreparedStatement pstmt = dbConn.prepareStatement(sql); request.setCharacterEncoding("UTF-8");
    String user
    = request.getParameter("username");
    String pass
    = request.getParameter("pass"); pstmt.setString(1, user);
    pstmt.setString(
    2, pass);
    ResultSet rs
    = pstmt.executeQuery();
    if(rs.next()) { %><center><h1>登陆成功!</h1></center><% } else { %><center><h1>登陆失败!</h1></center><% } %> </body> </html>

    运行结果如下

  • 相关阅读:
    JQuery学习笔记(1)——选择器
    Web前端——表单提交和Js添加选项
    Web前端——JavaScript练习
    Web前端——css
    Web前端——JavaScript笔记
    sirius的学习笔记(2)
    sirius的python学习笔记(1)
    Get和Post的请求
    IIS的配置
    一般处理程序aspx
  • 原文地址:https://www.cnblogs.com/yuezhihao/p/6434604.html
Copyright © 2011-2022 走看看