在jsp页面中验证

时间:2015-03-14 13:05:47

标签: java jsp

我正在使用一个表单,我将状态添加到数据库中,但现在我想对此表单使用服务器端验证(比如检查它是否为空。)所以请帮助我。 顺便说一句,我是jsp的新手,想在jsp页面学习服务器端验证,所以请告诉我如何解决它。
             

    String sql="insert into tblstate(fkCountry_Id,fldstate) "
            + "values('"+cou+"','"+sta+"')";
    try{
      conn.createStatement().executeUpdate(sql);
      conn.setAutoCommit(true);
      // New location to be redirected

    String site = new String("add_state.htm");
    response.setStatus(response.SC_MOVED_TEMPORARILY);
    response.setHeader("Location", site);

    }catch(Exception e){
      e.printStackTrace();
    }
%>
" method="POST">
                            <div class="control-group">
                                <label class="control-label" for="selectError">Country</label>
                                    <select class="form-control" name="cou">
                                        <option value="none">Select</option>
                                        <%
                                        String sql_cou = "select * from tblcountry";
                                        PreparedStatement coun=conn.prepareStatement(sql_cou);
                                        ResultSet rs_cou = coun.executeQuery(sql_cou);
                                        while(rs_cou.next()){
                                            out.println("<option value=" + rs_cou.getString("pkCountry_Id")+ "> " + rs_cou.getString("fldCountry")+"</option>");                                           
                                        }
                                        %>
                                    </select> 
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">State</label>
                                <input name="sta" type="text" class="form-control" id="exampleInputEmail1" placeholder="Enter Dzongkhag">
                            </div>
                            <button type="submit" class="btn btn-default">Submit</button>
                            <button type="reset" class="btn btn-default">Cancel</button>
                        </form>
                    </div>

0 个答案:

没有答案