河北省重大技术需求征集系统原型

博客 分享
0 218
优雅殿下
优雅殿下 2022-03-06 01:56:09
悬赏:0 积分 收藏

河北省重大技术需求征集系统原型

该项目今天全部完成套用了一个框架比较生疏,许多东西以后会完善的。

今天完善过程遇到很多问题后面会一个个列举并写出解决方法:

1、验证码问题(checkcode.java、login.jsp、login.java)

在后续代码中(checkcode.java、login.jsp、login.java)三部分展示。checkcode.java生成验证码图片在login.html中显示图片并设置点击事件,login.java中验证验证码的正确性,

2、框架页面点击跳转不存在于一个页面问题(代码在indexmain.jsp中)

用到了HTML中的<iframe标签>,标签定义及使用说明<iframe> ;标签规定一个内联框架。一个内联框架被用来在当前 HTML 文档中嵌入另一个文档。然后在点击链接中加入 target="mainframe"

target定义和用法

HTML5 不支持 <link> target 属性。target 属性规定在哪个窗口或框架中加载被链接文档。语法<link target="_blank|_self|_parent|_top|framename">

描述
_blank在新窗口中打开被链接文档。
_self默认。在相同的框架中打开被链接文档。
_parent在父框架集中打开被链接文档。
_top在整个窗口中打开被链接文档。
framename在指定的框架中打开被链接文档。

3、后台数据如何在HTMl显示

这一块用到了,html+ajax+servlet展示后台数据大家可以看大佬(5条消息) html+ajax+servlet展示后台数据_不吃豆芽儿的博客-CSDN博客

4、文本框输入500超出范围(zhengji.html)

这个问题取决于数据库的定义类型刚开始我定义的varchar类型后面查看资料采用text类型有的推荐使用longtext我的不能添加长度就直接过了,之后将文本框换为文本域该问题也就解决了

5、eclipse中jsp文件修改浏览器没有同步,问题之解决

jsp文件改了,但是浏览器显示的效果都没有变化。删了cookies,重启Tomcat都没解决。(有时可以解决)虽然只是小问题,但确实让人讨厌。

个人经验:碰到这种情况,右击Tomcat服务器,clean,再start一下就可以了!

其余便是一些小问题了,下面我先呈上本次项目的所有代码以及结构框架

前端

indexmain.jsp

<%@page import="util.util"%><%@page import="java.util.ArrayList"%><%@page import="java.util.List"%><%@page import="Bean.zhengjis"%><%@page import="Dao.dao"%><%@page import="javax.servlet.http.HttpSession"%><%@page import="javax.servlet.http.HttpServletRequest"%><%@page import="javax.servlet.http.HttpServletResponse"%><%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">    <head>        <meta charset="UTF-8">        <title>后台用户中心</title>        <link rel="stylesheet" type="text/css" href="statics/css/iconfont.css" />        <link rel="stylesheet" type="text/css" href="statics/css/style.css" />        <link rel="stylesheet" type="text/css" href="static/css/app.css"></link>        </head>    <body>            <%             HttpSession sess=request.getSession();            String name=(String) sess.getAttribute("name");//学生姓名            %>        <div class="header">            <div class="bar">                <div class="w1200">                    <span class="l">xxx网<font>用户中心</font></span>                    <span class="r"><a href="#"><i class="icon iconfont icon-dianyuan"></i>退出</a></span>                </div>            </div>            <div class="user-info">                <div class="w1200">                    <div class="user-headface">                        <img src="statics/images/user_face.jpg"/>                    </div>                    <div class="user-account">                        <p class="tip">下午好,<%=name%></p>                        <p class="account">                            <span>帐户名:<%=name%></span>                        </p>                </div>            </div>        </div></div>        <div class="main w1200">            <div class="left">                                <ul>                    <li>                        <a href="zhengji.html" target="mainframe" class="active">                            <i class="icon iconfont icon-lingdang"></i>                            需求征集                        </a>                    </li>                    <li>                        <a href="index.jsp?act=select2 "target="mainframe">                            <i class="icon iconfont icon-fangzidichan"></i>                            游览需求                        </a>                    </li>                    <li>                        <a href="index.jsp"target="mainframe">                            <i class="icon iconfont icon-wenda"></i>                            需求审核                        </a>                    </li>                    <li>                        <a href="register.html">                            <i class="icon iconfont icon-icon--"></i>                            用户注册                        </a>                    </li>                    <li>                        <a href="mima.html">                            <i class="icon iconfont icon-geren"></i>                            修改密码                        </a>                    </li>                </ul>            </div>            <div class="right">                <div class="tap">                    <span>系统消息</span>                </div>                  <div class="container-main">            <iframe name="mainframe" src="work.jsp" frameborder="0"width="1000"height="500" ></iframe>        </div>        </div></div>    </body></html>

login.java

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="renderer" content="webkit"/><meta name="force-rendering" content="webkit"/><title></title><link type="text/css" rel="stylesheet" href="css/style.css" /><script type="text/javascript" src="js/jquery-1.8.2.min.js"></script><script type="text/javascript">$(document).ready(function () {   var height=$(document).height();   $('body').css('height',height);   var mart=height-500;   mart = mart/2;   $('.loginBox').css('marginTop',mart);})</script><script>        onload = function () {            document.getElementById("img").onclick = function () {                this.src = "CheckCode?time"+new Date().getTime();            }        }    </script></head>S<body><form action="login" method="post"><div class="loginBox">  <h1>欢迎登陆</h1>  <div class="item">    <div class="icon"><img src="images/icon1.png" /></div>    <div class="txt"><input name="username" type="text" placeholder="请输入您的用户名"/></div>  </div>  <div class="item">    <div class="icon"><img src="images/icon2.png" /></div>    <div class="txt"><input name="password1" type="password" placeholder="请输入您的密码"/></div>  </div>    <div class="item">    <div class="icon"><img src="images/icon3.png" /></div>    <div class="txt">    <input type="text"  name="yanzhengma"placeholder="请输入验证码"  >         </div>       <div><img src="CheckCode" id="img" ></img></div>  </div>  <div class="item_3">    <input name="submi1" type="submit" onclick="sublim()" value="安全登录" class="btn"/>  </div>  <div class="item_4">    还没有账号?<a href="register.html">立即注册</a>  </div></div></from></body></html>

mima.java(修改密码)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="renderer" content="webkit"/><meta name="force-rendering" content="webkit"/><title></title><link type="text/css" rel="stylesheet" href="css/style.css" /><script type="text/javascript" src="js/jquery-1.8.2.min.js"></script><script type="text/javascript">$(document).ready(function () {   var height=$(document).height();   $('body').css('height',height);   var mart=height-500;   mart = mart/2;   $('.loginBox').css('marginTop',mart);})</script></head><body><form action="mima" method="post"><div class="loginBox">  <h1>注册</h1>  <div class="item">    <div class="icon"><img src="images/icon1.png" /></div>    <div class="txt"><input name="yonghu" type="text" placeholder="请输入您的用户名"/></div>  </div>  <div class="item">    <div class="icon"><img src="images/icon2.png" /></div>    <div class="txt"><input name="password" type="password" placeholder="请输入您的新密码"/></div>  </div>   <div class="item">    <div class="icon"><img src="images/icon2.png" /></div>    <div class="txt"><input name="password1" type="password" placeholder="请再次输入您的密码"/></div>  </div>  <div class="item_3">    <input name="" type="submit" value="修改" class="btn"/>  </div>  <div class="item_4">    已注册<a href="index.html">返回</a>  </div></div></form></body></html>

register.java

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="renderer" content="webkit"/><meta name="force-rendering" content="webkit"/><title></title><link type="text/css" rel="stylesheet" href="css/style.css" /><script type="text/javascript" src="js/jquery-1.8.2.min.js"></script><script type="text/javascript">$(document).ready(function () {   var height=$(document).height();   $('body').css('height',height);   var mart=height-500;   mart = mart/2;   $('.loginBox').css('marginTop',mart);})</script></head><body><form action="register" method="post"><div class="loginBox">  <h1>注册</h1>  <div class="item">    <div class="icon"><img src="images/icon1.png" /></div>    <div class="txt"><input name="yonghu" type="text" placeholder="请输入您的用户名"/></div>  </div>  <div class="item">    <div class="icon"><img src="images/icon2.png" /></div>    <div class="txt"><input name="password" type="password" placeholder="请输入您的密码"/></div>  </div>   <div class="item">    <div class="icon"><img src="images/icon2.png" /></div>    <div class="txt"><input name="password1" type="password" placeholder="请再次输入您的密码"/></div>  </div>   <div class="item">    <div class="icon"><img src="images/icon2.png" /></div>    <div class="txt"><input name="id" id="id" type="text" placeholder="手机号码" onblur="isCardNo(this.value)" />    </div>  </div>     <div class="item">    <div class="icon"><img src="images/icon2.png" /></div>    <div class="txt"><input name="address" type="text" placeholder="所属单位"/></div>  </div>      <div class="item_3">    <input name="" type="submit" value="注册" class="btn"/>  </div>  <div class="item_4">    已注册<a href="login.html">我要登录</a>  </div></div></form></body><script type="text/javascript">function isCardNo(card) {   var reg = /(^\d{11}$)/;    if(reg.test(card) === false)   {     alert("电话号码不为11位");     document.getElementById('id').value="";  } }</script></html>

work.jsp(无用东西可加可不加)

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <meta http-equiv="X-UA-Compatible" content="ie=edge">    <title>jQuery/HTML5/css3精美唯美图片Y轴展示</title>        <link rel="stylesheet" href="bbb/css/style.css">    </head><body>       <div class="wrapper init">        <ul class="content">            <li class="item" >                <div class="inner">                    <div class="bjPic" ></div>                    <div class="dir" >                        <h2>那一瞬</h2>                    </div>                    <div class="showBox">                        <div class="showBox-dir" >                            <h2>  那一瞬,我飞升成仙,不为长生,只为佑你平安喜乐</h2></a>                                                   </div>                        <div class="close">                        </div>                    </div>                </div>            </li>            <li class="item">                <div class="inner">                    <div class="bjPic"></div>                    <div class="dir">                        <h2>那一刻</h2>                    </div>                    <div class="showBox">                        <div class="showBox-dir">                            <h2>那一刻,我升起风马,不为祈福,只为守候你的到来</h2>                        </div>                        <div class="close">                        </div>                    </div>                </div>            </li>            <li class="item">                <div class="inner">                    <div class="bjPic"></div>                    <div class="dir">                        <h2>那一日</h2>                    </div>                    <div class="showBox">                        <div class="showBox-dir">                            <h2>那一日,我磨一砂石,不为修性,只为丢进你的心海</h2>                        </div>                        <div class="close">                        </div>                    </div>                </div>            </li>            <li class="item">                <div class="inner">                    <div class="bjPic"></div>                    <div class="dir">                        <h2>那一夜</h2>                    </div>                    <div class="showBox">                        <div class="showBox-dir">                            <h2>那一夜,我彻宿低吟,不为参悟,只为寻你的气息</h2>                        </div>                        <div class="close">                        </div>                    </div>                </div>            </li>            <li class="item">                <div class="inner">                    <div class="bjPic"></div>                    <div class="dir">                        <h2>那一天</h2>                    </div>                    <div class="showBox">                        <div class="showBox-dir">                            <h2>那一天,闭目在经殿香雾中,蓦然听见,你颂经中的真言</h2>                        </div>                        <div class="close">                        </div>                    </div>                </div>            </li>            <li class="item">                <div class="inner">                    <div class="bjPic"></div>                    <div class="dir">                        <h2>那一月</h2>                    </div>                    <div class="showBox">                        <div class="showBox-dir">                            <h2>那一月,我摇动所有经筒,不为超度,只为触摸你指尖</h2>                        </div>                        <div class="close">                        </div>                    </div>                </div>            </li>            <li class="item">                <div class="inner">                    <div class="bjPic"></div>                    <div class="dir">                        <h2>那一年</h2>                    </div>                    <div class="showBox">                        <div class="showBox-dir">                            <h2>那一年,磕长头匍匐在山路,不为觐见,只为贴着你的温暖</h2>                        </div>                        <div class="close">                        </div>                    </div>                </div>            </li>            <li class="item">                <div class="inner">                    <div class="bjPic"></div>                    <div class="dir">                        <h2>那一世</h2>                    </div>                    <div class="showBox">                        <div class="showBox-dir">                        <a href="index.jsp"></a>                            <h2>那一世,转山转水转佛塔,不为修来世,只为途中相见</h2>                        </div>                        <div class="close">                        </div>                    </div>                </div>            </li>        </ul>    </div>        <script src="bbb/js/jquery.min.js"></script>    <script src="bbb/js/index.js"></script>    <script src="bbb/js/snowflake.js"></script>    </body></html>

zhengji.html(征集信息填报)

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title><SCRIPT LANGUAGE="JavaScript">        var strTime, strDate;        function webClock()        {            var dNow = new Date();            var dHours = dNow.getHours();            var dMinutes = dNow.getMinutes();            var dSeconds = dNow.getSeconds();            strTime = dHours;            strTime += ((dMinutes<10) ? ":0" : ":") + dMinutes;            strTime += ((dSeconds<10) ? ":0" : ":") + dSeconds;            clock.time.value = strTime;                        var dDate = dNow.getDate();            var dMonth = dNow.getMonth() + 1;            var dYear = dNow.getYear();            strDate = dMonth;            strDate += ((dDate<10) ? "/0" : "/") + dDate;            strDate += "/" + dYear;            clock.date.value = strDate;            setTimeout("webClock()",1000);        }    </SCRIPT></head>    </HTML><body ONLOAD="webClock()">    <h1 class="callout" align="center">河北省重大技术需求征集表</h1><form action="zhengji1" method="post"align="center" >        <table class="wzc-table" border="1" cellspacing="0">             <tr>                <th>技术需求名称:</th>                <td><input type="text"  name="mingcheng" size="20" ></td>            </tr>            <tr>                <th>重大科技需求概述:</th>            <td colspan="3">             <textarea cols="100" rows="5"name="gaishu"></textarea>        </td>            </tr>            <tr>            <th>研究类型:</th>                <td>                <input type="checkbox" name="leixing" value="基础研究 ">基础研究                 <input type="checkbox" name="leixing" value="应用研究">应用研究                <input type="checkbox" name="leixing" value="试验发展">试验发展                <input type="checkbox" name="leixing" value="研究发展与成果应用">研究发展与成果应用                 <input type="checkbox" name="leixing" value="技术推广与科技服务  ">技术推广与科技服务             </td>            </tr>            <tr>                <th>时间:</th>                <td><input type="text"  name="date" size="20" ></td>            </tr>          <tr>          <th>技术需求合作模式:</th>                   <td>                  <input type="radio" name="moshi" value="独立开发">独立开发                      <input type="radio" name="moshi" value="技术转让" checked>技术转让                 <input type="radio" name="moshi" value="合作开发">合作开发                     <input type="radio" name="moshi" value="技术入股">技术入股                     </td>                     </tr>                      <tr>                <th>计划总投资</th>                <td><input type="text"  name="touzi" size="20" ></td>            </tr>                        <tr >            <td></td>                <td ><input type="submit" value="提交" class="wzc-btn" ></td>            </tr>                     </table>    </form></body></html>

index.jsp(显示所有基本数据并不完善)

<%@page import="util.util"%><%@page import="java.util.ArrayList"%><%@page import="java.util.List"%><%@page import="Bean.zhengjis"%><%@page import="Dao.dao"%><%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html><html><head><meta charset="UTF-8"><title>展示数据</title> <link rel="stylesheet" href="./layui/css/layui.css"><script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>  <script> layui.use('form', function() { var form = layui.form; form.render(); }); </script></head><body><form action="select" method="post">    <table class="layui-table">    <colgroup>    <col width="150">    <col width="200">    <col>  </colgroup>  <thead>        <tr>            <th>序号</th>            <th>技术需求名称</th>            <th>提交日期</th>            <th>需求状态</th>        </tr>        </thead>        <tbody>    <%        ArrayList <zhengjis> zhengjis = new ArrayList<zhengjis>();        dao dao = new dao();        int num=0;            dao.showall(zhengjis);            for (int i =0; i < zhengjis.size(); i++) {                zhengjis A = zhengjis.get(i);                    num+=1;        %>        <tr>        <td><%=num%></td>            <td><a href="select?mm=<%=A.getMingcheng()%>"><%=A.getMingcheng()%></a></td>            <th><%=A.getDate() %></th>                    <td><%=A.getShenghe()%></td>                </tr>        <%            }        %>                </tbody>            </table></body></html>

index2.jsp(显示查询信息此jsp文件与index.jsp相关联无法自己启动会因为要从index.jsp获取数据)

<%@page import="util.util"%><%@page import="java.util.ArrayList"%><%@page import="java.util.List"%><%@page import="Bean.zhengjis"%><%@page import="Dao.dao"%><%@page import="servlet.shenhe"%><%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html><html><head><meta charset="UTF-8"><title>展示数据</title> <link rel="stylesheet" href="./layui/css/layui.css"><script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>  <script> layui.use('form', function() { var form = layui.form; form.render(); }); </script></head><body><form action="shenhe" method="post" align="center">        <table class="layui-table">    <colgroup>    <col width="150">    <col width="200">    <col>  </colgroup>  <thead>        <tr>            <th>技术需求名称</th>            <th>重大科技需求概述</th>            <th>研究类型</th>            <th>技术需求合作模式</th>            <th>计划总投资</th>        </tr>        </thead>        <tbody>    <%        ArrayList <zhengjis> zhengjis =(ArrayList<zhengjis>)request.getAttribute("zhengji");;                int num=0;            for (int i =0; i < zhengjis.size(); i++) {                zhengjis A = zhengjis.get(i);            %>        <tr>        <td><%=A.getMingcheng()%></td>        <td><%=A.getGaishu()%></td>        <td><%=A.getLeixing() %></td>        <td><%=A.getMoshi()%></td>            <td><%=A.getTouzi()%></td>            <td><a href="shenhe?mm=<%=A.getMingcheng()%>&nn=<%=1%>"><input type = "button" onclick = "btnRst_Click()" value = "审核通过" ></a>                        <script>                            function btnRst_Click()                             {                                    undefined                                alert("审核通过");                            }                        </script>                                   </input></td>                                <td><a href="shenhe?mm=<%=A.getMingcheng()%>&nn=<%=0%>"><input type = "button" onclick = "btnRst_Click2()" value = "审核不通过" >                        <script>                            function btnRst_Click2()                             {undefined                                alert("审核不通过");                            }                        </script>                                   </input></td>            </tr>        <%            }        %>    </tbody>    </table></body></html>

 

后端:

Bean包

user.java

package Bean;public class user {private String number;private String password;private String phone;private String address;public String getNumber() {    return number;}public void setNumber(String number) {    this.number = number;}public String getPassword() {    return password;}public void setPassword(String password) {    this.password = password;}public String getPhone() {    return phone;}public void setPhone(String phone) {    this.phone = phone;}public String getAddress() {    return address;}public void setAddress(String address) {    this.address = address;}}

zhengjis.java

package Bean;public class zhengjis {    private String mingcheng;    private String gaishu;    private String leixing;    private String moshi;    private String touzi;    private String shenghe;    private String date;    public String getDate() {        return date;    }    public void setDate(String date) {        this.date = date;    }    public String getMingcheng() {        return mingcheng;    }    public void setMingcheng(String mingcheng) {        this.mingcheng = mingcheng;    }    public String getShenghe() {        return shenghe;    }    public void setShenghe(String shenghe) {        this.shenghe = shenghe;    }    public String getGaishu() {        return gaishu;    }    public void setGaishu(String gaishu) {        this.gaishu = gaishu;    }    public String getLeixing() {        return leixing;    }    public void setLeixing(String leixing) {        this.leixing = leixing;    }    public String getMoshi() {        return moshi;    }    public void setMoshi(String moshi) {        this.moshi = moshi;    }    public String getTouzi() {        return touzi;    }    public void setTouzi(String touzi) {        this.touzi = touzi;    }    }

Dao包下(工具类):

dao.java

package Dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import Bean.user;import Bean.zhengjis;import util.util;public class dao {    public void add(user A) throws ClassNotFoundException, SQLException {        Connection connection = util.getConnection();        String sql = "insert into user(number,password,phone,address) values(?,?,?,?)";        PreparedStatement preparedStatement = null;        try {             //????????????             preparedStatement = connection.prepareStatement(sql);           // preparedStatement = connection.prepareStatement(sql);             preparedStatement.setString(1, A.getNumber());             preparedStatement.setString(2, A.getPassword());             preparedStatement.setString(3, A.getPhone());             preparedStatement.setString(4, A.getAddress());             preparedStatement.executeUpdate();             } catch (SQLException e) {                // TODO Auto-generated catch block               e.printStackTrace();            }finally {            }    }    public void add1(zhengjis A) throws ClassNotFoundException, SQLException {        Connection connection = util.getConnection();        String sql = "insert into zhengji(mingcheng,gaishu,leixing,moshi,touzi,shenghe,shijian) values(?,?,?,?,?,?,?)";        PreparedStatement preparedStatement = null;        try {             //????????????             preparedStatement = connection.prepareStatement(sql);           // preparedStatement = connection.prepareStatement(sql);             preparedStatement.setString(1, A.getMingcheng());             preparedStatement.setString(2, A.getGaishu());             preparedStatement.setString(3, A.getLeixing());             preparedStatement.setString(4, A.getMoshi());             preparedStatement.setString(5, A.getTouzi());             preparedStatement.setString(6, A.getShenghe());             preparedStatement.setString(7, A.getDate());             preparedStatement.executeUpdate();             } catch (SQLException e) {                // TODO Auto-generated catch block               e.printStackTrace();            }finally {            }    }    public void xiugaimima(String yonghu,String password2) throws ClassNotFoundException, SQLException {        Connection connection = util.getConnection();        String sql = " update user set password = ? where number = ?";        PreparedStatement preparedStatement = null;        try {             //????????????             preparedStatement = connection.prepareStatement(sql);           // preparedStatement = connection.prepareStatement(sql);                        preparedStatement.setString(1, password2);             preparedStatement.setString(2, yonghu);             preparedStatement.executeUpdate();             } catch (SQLException e) {                // TODO Auto-generated catch block               e.printStackTrace();            }finally {            }}        public void showall(ArrayList<zhengjis> ke) throws ClassNotFoundException, SQLException{                         String sql1 ="select * from zhengji";              //????????????             Connection connection = util.getConnection();                 try {                     PreparedStatement ps = connection.prepareStatement(sql1);                     ResultSet rs =  ps.executeQuery();                                      while(rs.next()) {                     System.out.println("1”");                    zhengjis A = new zhengjis();                    A.setMingcheng(rs.getString(1));                    A.setShenghe(rs.getString(6));                    A.setDate(rs.getString(7));                     ke.add(A);                   }                 } catch (SQLException e) {                        // TODO Auto-generated catch block                        e.printStackTrace();                    }                }        public void showall1(ArrayList<zhengjis> ke) throws ClassNotFoundException, SQLException{                         String sql1 ="select * from zhengji";              //????????????             Connection connection = util.getConnection();                 try {                     PreparedStatement ps = connection.prepareStatement(sql1);                     ResultSet rs =  ps.executeQuery();                                      while(rs.next()) {                     System.out.println("1”");                    zhengjis A = new zhengjis();                    A.setMingcheng(rs.getString(1));                    A.setGaishu(rs.getString(2));                    A.setLeixing(rs.getString(3));                    A.setMoshi(rs.getString(4));                    A.setTouzi(rs.getString(5));                    A.setShenghe(rs.getString(6));                     ke.add(A);                   }                 } catch (SQLException e) {                        // TODO Auto-generated catch block                        e.printStackTrace();                    }                }        public void update(String mm,String result) throws ClassNotFoundException, SQLException {            Connection connection = util.getConnection();            String sql = "update zhengji set shenghe = ?  where    mingcheng = ?";            PreparedStatement preparedStatement = null;            try {                 //????????????                 preparedStatement = connection.prepareStatement(sql);               // preparedStatement = connection.prepareStatement(sql);                 preparedStatement.setString(1,result);                 preparedStatement.setString(2, mm);                 preparedStatement.executeUpdate();                 } catch (SQLException e) {                    // TODO Auto-generated catch block                   e.printStackTrace();                }finally {                }        }        public void select(ArrayList<zhengjis> zhengjis,String name) throws ClassNotFoundException, SQLException{             String sql1 ="select * from zhengji where mingcheng = ?";             Connection connection = util.getConnection();                 try {                     PreparedStatement ps = connection.prepareStatement(sql1);                      ps.setString(1, name);                     ResultSet rs =  ps.executeQuery();                   while(rs.next()) {                     zhengjis A = new zhengjis();                                          A.setGaishu(rs.getString(2));                     A.setLeixing(rs.getString(3));                     A.setMoshi(rs.getString(4));                     A.setTouzi(rs.getString(5));                     A.setMingcheng(rs.getString(1));                     zhengjis.add(A);                   }                 } catch (SQLException e) {                        // TODO Auto-generated catch block                        e.printStackTrace();                    }                }//    }//    public void add2(agent A) throws ClassNotFoundException, SQLException {//        Connection connection = util.getConnection();//        String sql = "insert into agent(AgentAddress,AgentName,AgentID,AgentPhone) values(?,?,?,?)";//        PreparedStatement preparedStatement = null;//        try {//             //????????????//             preparedStatement = connection.prepareStatement(sql);//           // preparedStatement = connection.prepareStatement(sql);//             preparedStatement.setString(1, A.getAgentAddress());//             preparedStatement.setString(2, A.getAgentName());//             preparedStatement.setString(3, A.getAgentID());//             preparedStatement.setString(4, A.getAgentPhone());//             preparedStatement.executeUpdate();//             } catch (SQLException e) {//                // TODO Auto-generated catch block//               e.printStackTrace();//            }finally {////            }//    }}

servlet包下:

checkcode.java:这个文件中是我遇到的第一个问题验证码,主要生成验证码的图片再通过session获取生成验证码数据在login.java里进行与前端的数据比较

package servlet;import javax.imageio.ImageIO;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.annotation.*;import java.awt.*;import java.awt.image.BufferedImage;import java.io.IOException;import java.util.Random;@WebServlet(name = "CheckCode", value = "/CheckCode")public class CheckCode extends HttpServlet {    @Override    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        //创建一个对象        int width = 100;        int height = 50;        BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);        //填充背景颜色        Graphics g = image.getGraphics();//画笔        g.setColor(Color.cyan);//设置画笔颜色        g.fillRect(0,0,width,height);        //画边框        g.setColor(Color.black);        g.drawRect(0,0,width-1,height-1);        //随机码        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";        Random ran = new Random();        StringBuilder sb = new StringBuilder();        for(int i=1;i<=4;i++){            int index = ran.nextInt(str.length());            char ch = str.charAt(index);            sb.append(ch);            g.drawString(ch+"",width/5*i,height/2);        }        String checkCode_session = sb.toString();        //将验证码存入session        request.getSession().setAttribute("checkCode_session",checkCode_session);        //随机划线        g.setColor(Color.BLUE);        for(int i=1;i<4;i++){            int x1 = ran.nextInt(width);            int y1 = ran.nextInt(height);            int x2 = ran.nextInt(width);            int y2 = ran.nextInt(height);            g.drawLine(x1,y1,x2,y2);        }        //图片输出        ImageIO.write(image,"png",response.getOutputStream());    }    @Override    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        this.doPost(request,response);    }}

login.java:这个登录我加入了一些账号、密码、验证码是否存在是否正确并给出相应的结果。

package servlet;import java.io.IOException;import java.io.PrintWriter;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import javax.swing.WindowConstants;import Bean.user;import util.util;/** * Servlet implementation class register */@WebServlet("/login")public class login extends HttpServlet {    private static final long serialVersionUID = 1L;           /**     * @see HttpServlet#HttpServlet()     */    public login() {        super();        // TODO Auto-generated constructor stub    }    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doPost(request,response);    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub                // TODO Auto-generated method stub                        request.setCharacterEncoding("utf-8");                        //????????????????                        int index=-1;                        response.setContentType("text/html;charset=utf-8");//设置字符集                        String usernames = request.getParameter("username");                        String passwords=request.getParameter("password1");                        String works=request.getParameter("work");                        String verifyc  = request.getParameter("yanzhengma");                        HttpSession sess=request.getSession();                        String name11=(String) sess.getAttribute("checkCode_session");//验证码                        System.out.println(name11);                        String svc =(String) request.getSession().getAttribute("sessionverify");                        PrintWriter out=response.getWriter();                        HttpSession session=request.getSession();                        session.setAttribute("name", usernames);//获取登录者信息                        Connection connection = null;                        int i=0;int count=0;                                    String username1[]=new String[50];                        String password2[]=new String[50];                        String shenfen1[]=new String[50];                        try {                            connection = util.getConnection();                        } catch (ClassNotFoundException | SQLException e) {                            // TODO Auto-generated catch block                            e.printStackTrace();                        }                        PreparedStatement pre = null;                        try {                            pre = connection.prepareStatement("select * from user");                        } catch (SQLException e1) {                            // TODO Auto-generated catch block                            e1.printStackTrace();                        }                        ResultSet set = null;                        try {                            set = pre.executeQuery("select * from user");                        } catch (SQLException e) {                            // TODO Auto-generated catch block                            e.printStackTrace();                        }                         try {                            while(set.next())                            {                                username1[i]=set.getString("number");                                password2[i]=set.getString("password");                                i++;                                count++;                            }                        } catch (SQLException e1) {                            // TODO Auto-generated catch block                            e1.printStackTrace();                        }                        if(verifyc.equals(name11))                        {                            System.out.println("验证码");                                                for(int j=0;j<count;j++) {                        if(username1[j].equals(usernames))                        {                                                        System.out.println("dasdasd");                            if(password2[j].equals(passwords))                            {                                System.out.println("shuichen");                                    index=1;                                    response.sendRedirect("indexmain.jsp");                            }                            else                            {                                                    System.out.println("chen");                                out.print("<script>alert('密码错误');window.location.href='login.html'</script>");                            }                        }                        else                         {                            System.out.println("huo");                            out.print("<script>alert('输入账号不存在请重新输入');window.location.href='login.html'</script>");                        }                        }                                                }                        else                        {                            out.print("<script>alert('验证码错误请重新输入');window.location.href='login.html'</script>");                        }//                        System.out.println(number);            }}

mima.java(这个时用来修改密码的其中包括密码比较等)

package servlet;import java.io.IOException;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import Dao.dao;import util.util;import Bean.user;/** * Servlet implementation class dengji */@WebServlet("/mima")public class mima extends HttpServlet {    private static final long serialVersionUID = 1L;           /**     * @see HttpServlet#HttpServlet()     */    public mima() {        super();        // TODO Auto-generated constructor stub    }    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doPost(request, response);    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    // TODO Auto-generated method stub    request.setCharacterEncoding("utf-8");    //????????????????    response.setContentType("text/html;charset=utf-8");//???????????,?????????????System.out.println("dasdasd");String yonghu=request.getParameter("yonghu");String password=request.getParameter("password");String password1=request.getParameter("password1");if(password.equals(password1)) {        Connection connection = null;int i=0;int count=0;String username1[]=new String[50];dao A=new dao();try {    connection = util.getConnection();} catch (ClassNotFoundException | SQLException e) {    // TODO Auto-generated catch block    e.printStackTrace();}PreparedStatement pre = null;try {    pre = connection.prepareStatement("select * from user");} catch (SQLException e1) {    // TODO Auto-generated catch block    e1.printStackTrace();}ResultSet set = null;try {    set = pre.executeQuery("select * from user");} catch (SQLException e) {    // TODO Auto-generated catch block    e.printStackTrace();} try {    while(set.next())    {        username1[i]=set.getString("number");        System.out.println(username1[i]);        i++;        count++;    }} catch (SQLException e1) {    // TODO Auto-generated catch block    e1.printStackTrace();}for(int j=0;j<count;j++) {    if(username1[j].equals(yonghu))    {                            try {                    A.xiugaimima(yonghu, password1);                } catch (ClassNotFoundException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                } catch (SQLException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                }    }}}else{    response.getWriter().print("<script>alert('输入密码错误请重新输入!');window.location.href='mima.html'</script>");}}}

register.java(注册)

package servlet;import java.io.IOException;import java.sql.SQLException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import Dao.dao;import Bean.user;/** * Servlet implementation class dengji */@WebServlet("/register")public class register extends HttpServlet {    private static final long serialVersionUID = 1L;           /**     * @see HttpServlet#HttpServlet()     */    public register() {        super();        // TODO Auto-generated constructor stub    }    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doPost(request, response);    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        request.setCharacterEncoding("utf-8");        //????????????????        response.setContentType("text/html;charset=utf-8");//???????????,?????????????                dao A =new dao();        String password = request.getParameter("password");        String username=request.getParameter("yonghu");        String phone=request.getParameter("id");        String password1=request.getParameter("password1");        String address=request.getParameter("address");        if(password.equals(password1))        {user B = new user();        B.setNumber(username);        B.setPassword(password);        B.setPhone(phone);        B.setAddress(address);        try {            A.add(B);        } catch (ClassNotFoundException | SQLException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }                    }        else {            System.out.println("密码");            response.getWriter().print("<script>alert('输入密码错误请重新输入!');window.location.href='register.html'</script>");            }    }}

select.java

package servlet;import java.io.IOException;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import Bean.zhengjis;import Dao.dao;import util.util;/** * Servlet implementation class add */@WebServlet("/select")public class select extends HttpServlet {    private static final long serialVersionUID = 1L;           /**     * @see HttpServlet#HttpServlet()     */    public select() {        super();        // TODO Auto-generated constructor stub    }    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doPost(request,response);    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub                // TODO Auto-generated method stub            request.setCharacterEncoding("utf-8");                        response.setContentType("text/html;charset=utf-8");            String mingcheng = request.getParameter("mm");;            ArrayList <zhengjis> zhengji = new ArrayList<zhengjis>();            dao dao=new dao();            if(mingcheng!=null)            {                try {                    dao.select(zhengji,mingcheng);                } catch (ClassNotFoundException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                } catch (SQLException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                }                request.setAttribute("zhengji",zhengji);//setAttribute() 方法添加指定的属性,并为其赋指定的值。                request.getRequestDispatcher("index2.jsp").forward(request, response);                            }            else {                response.getWriter().write("查询数据不存在请重新输入。");            }//            else if(number!=null)    {//                    try {//                        dao.select1(book,number);//                    } catch (ClassNotFoundException e) {//                        // TODO Auto-generated catch block//                        e.printStackTrace();//                    } catch (SQLException e) {//                        // TODO Auto-generated catch block//                        e.printStackTrace();//                    }//                    request.setAttribute("people",people);//                    request.getRequestDispatcher("chakan.jsp").forward(request, response);//                }//            else if(minzu!=null)    {//                    try {//                        dao.select4(people,minzu);//                    } catch (ClassNotFoundException e) {//                        // TODO Auto-generated catch block//                        e.printStackTrace();//                    } catch (SQLException e) {//                        // TODO Auto-generated catch block//                        e.printStackTrace();//                    }//                    request.setAttribute("people",people);//                    request.getRequestDispatcher("chakan.jsp").forward(request, response);//                }//                else     {//                    try {//                        dao.select5(people,jiaoyuchengdu);//                    } catch (ClassNotFoundException e) {//                        // TODO Auto-generated catch block//                        e.printStackTrace();//                    } catch (SQLException e) {//                        // TODO Auto-generated catch block//                        e.printStackTrace();//                    }//                    request.setAttribute("people",people);//                    request.getRequestDispatcher("chakan.jsp").forward(request, response);//                }                                    }}

shenhe.java对数据进行审核

package servlet;import java.io.IOException;import java.io.PrintWriter;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import javax.swing.WindowConstants;import Bean.user;import Bean.zhengjis;import util.util;import Dao.dao;/** * Servlet implementation class sehnhe */@WebServlet("/shenhe")public class shenhe extends HttpServlet {    private static final long serialVersionUID = 1L;           /**     * @see HttpServlet#HttpServlet()     */    public shenhe() {        super();        // TODO Auto-generated constructor stub    }    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doPost(request, response);    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub                request.setCharacterEncoding("utf-8");                //????????????????                response.setContentType("text/html;charset=utf-8");//???????????,?????????????                System.out.println("chen");                String mm=request.getParameter("mm");                String nn=request.getParameter("nn");                dao A=new dao();                String result="";                System.out.println(mm);                if(nn.equals("1"))                {                    result="通过";                }                else                {                    result="未通过";                }                zhengjis B = new zhengjis();                                try {                    A.update(mm,result);                                     } catch (ClassNotFoundException | SQLException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                }                response.sendRedirect("index.jsp");            }    }

zhengji1.java(相当于上传一个数据表了)

package servlet;import java.io.IOException;import java.sql.SQLException;import java.util.Arrays;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import Bean.zhengjis;import Dao.dao;/** * Servlet implementation class zhengji1 */@WebServlet("/zhengji1")public class zhengji1 extends HttpServlet {    private static final long serialVersionUID = 1L;           /**     * @see HttpServlet#HttpServlet()     */    public zhengji1() {        super();        // TODO Auto-generated constructor stub    }    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doPost(request, response);    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        request.setCharacterEncoding("utf-8");        //????????????????        response.setContentType("text/html;charset=utf-8");//???????????,?????????????                dao A =new dao();        String mingcheng = request.getParameter("mingcheng");        String gaishu=request.getParameter("gaishu");        String leixing=request.getParameter("leixing");        String [] lei  = request.getParameterValues("leixing");         leixing = Arrays.toString(lei);        String moshi=request.getParameter("moshi");        String touzi=request.getParameter("touzi");        String shijian=request.getParameter("date");//        System.out.println();        System.out.println(mingcheng);        String shenghe="未审核";        zhengjis B = new zhengjis();        System.out.println("213123");            B.setMingcheng(mingcheng);            B.setGaishu(gaishu);            B.setLeixing(leixing);            B.setTouzi(touzi);            B.setMoshi(moshi);            B.setShenghe(shenghe);            B.setDate(shijian);        try {                A.add1(B);        } catch (ClassNotFoundException | SQLException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        response.getWriter().print("<script>alert('征集上传成功请等候消息');window.location.href='index.html'</script>");        }            }

 这是本次项目文件以及css样式大家可以提取

链接:https://pan.baidu.com/s/1gHHWfzzsG6fwdv1Mmdv10A
提取码:jyt9

posted @ 2022-03-05 23:52 O_O似曾相识 阅读(1) 评论(0) 编辑 收藏 举报
回帖
    优雅殿下

    优雅殿下 (王者 段位)

    2018 积分 (2)粉丝 (47)源码

    小小码农,大大世界

     

    温馨提示

    亦奇源码

    最新会员