java如何让注册的用户名不重复,在当前页面就可以判断,并抛出提示?

差的资。料说是用ajax做?可是我不会ajax,ajax实在不会写了。。。


html部分


<p>

        <label>编号:</label> <input name="custom_number" type="text" size="30" id="custom_number"

                    value="<%=item.getCustom_number() == null ? "" : item.getCustom_number()%>"

                    maxlength="50" />

</p>

javascript部分


<script>

$('#custom_number').change(function(){    

                $.ajax({    

        url: '<%=basePath%>admin/custom/repeat.html?custom_number=' + $('#custom_number').val(),

        dataType: 'post',

        

        });

</script>


后台数据库代码


 @RequestMapping(value = "/repeat")

     public void repeat(HttpServletRequest request, HttpServletResponse response, String custom_number) throws SQLException, IOException{

         ConnectionSource connectionSource = DBUtil.getConnectionSource();

         

         Dao<zqbp_custom, String> dao = DaoManager.createDao(connectionSource,

                 zqbp_custom.class);

         

         QueryBuilder<zqbp_custom, String> where = dao.queryBuilder();

         List<zqbp_custom> list = where.where().eq("custom_number", custom_number).query();

         if(list.size()==0){

             

         }else {

             response.getWriter().write("编号重复,请重新输入");

              response.getWriter().close();

        }

     }


德玛西亚99
浏览 2080回答 3
3回答

HUH函数

1.你后台肯定得检索数据库。2.前台直接判断就得发送请求。3.你不想跳转,那只能是ajax发送请求。你上网google一个例子,我就不当搬运工了,ajax就是个js发送http请求。另外题主你说java?还是javascript?

元芳怎么了

jquery validation找个这个来用当然自己做也没什么难的 最多做的丑一点
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java