标签:例子 protect for exce 读取 input prepare method print
1.完成过程遇到几个问题:
1.1 用js实现注册手机号、邮箱、确认密码验证
首先要确定验证的正则表达式,网上有很多版本,其次难住的地方是无法引用,因为对js不熟悉,所以犯了很多”愚蠢“的错误。比如,js应写在body外面;值的传递是通过是value来进行的;引用onblur事件来触发函数。举个例子:
手 机 号:<input class="layui-btn layui-btn-primary layui-btn-radius" type="text" name="telephone" id="telephone" onblur="upperCase(this.value)" /><br>
script对应的代码 :
<script type="text/javascript"> function upperCase(val){ //var val=document.getElementById(phone).value; var reg=/^1[345678]\d{9}$/; if (val==‘‘) { alert("请输入手机号!") }else if(reg.test(val)){ }else{ alert("手机号输入错误,请重新输入!!") } } </script>
2.session的使用
实现创新年报搜索相关平台信息时用到了session传值
基本思路为:用list来传值平台类的属性值,用session的setAttribute来存一个对象,在jsp中用getAttribute来读取。举个例子:
servlet类
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub req.setCharacterEncoding("utf-8"); String condition1 = req.getParameter("condition1"); String content1 = req.getParameter("content1"); String sql = "select PId,Pname,Pnum,approval_num,techField from platform where "+condition1+" like ‘%"+content1+"%‘"; Connection conn = DBUtil.getConnection(); PreparedStatement prep = null; ResultSet rs = null; List<platform> list = new ArrayList<platform>(); HttpSession session = req.getSession(); try { prep = conn.prepareStatement(sql); rs = prep.executeQuery(); while(rs.next()) { platform platform = new platform(); platform.setPId(rs.getInt(1)); platform.setPname(rs.getString(2)); platform.setPnum(rs.getDate(3)); platform.setApproval_num(rs.getString(4)); platform.setTechField(rs.getString(5)); list.add(platform); } session.setAttribute("platforms", list); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } resp.sendRedirect("/Innovation/NewSearch2.jsp"); }
标签:例子 protect for exce 读取 input prepare method print
原文地址:https://www.cnblogs.com/-2016/p/10328027.html