有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javascript在jsp页面中添加验证,但在控制台中仍然显示一些错误

您好,我正在我的JSP页面中添加验证,它可以工作,但在控制台中仍然显示错误为空异常

这是我为验证准备的函数

function countriesInfo(){
             var a = document.forms["countries"]["countryname"].value;
            var x = document.forms["countries"]["description"].value;
            if (a == null || a == "") {
                alert("Name must be filled out");
                return false;
            }
            if(x.length > 2000){
                alert("Description should be maximum of 2000 characters");
                return false;
            }//else{
                //return true;
                //}
        }  

下面是我的JSP页面表单

<form name="countries"action="/RouternData/roternInternal" method="post"  onsubmit="return countriesInfo()">
                <input type='hidden'  value='YES' name='SAVECONTRYDETAILS' /> 
                <div class="panel panel-default">
                <div class="panel-heading"><h2>Enter countries detail</h2></div>
                <div class="panel-body">
                    <table class="table1" border="0">
                        <tbody>


                            <tr>
                                <td colspan="2">
                                    <div class="input-group">
                                        <span class="input-group-addon"><i class="fa fa-globe fa-lg"></i></span>
                                        <input class="form-control" type="text" placeholder=" Enter country name" name="countryname" id="countryName" required>

                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <div class="input-group">
                                        <span class="input-group-addon" ><i class="fa fa-info fa-lg"></i></span>
                                        <textarea class="form-control" type="textarea" placeholder="Country description" name="description" id="countrydescription" ></textarea>

                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td >


                                 </td>
                                 <td >
                                 <button type="submit" class="btn btn-default btn-lg" onclick="saveCountry()" > Submit</button>
                                    <button type="reset" class="btn btn-default btn-lg">reset</button>
                                 </td>
                            </tr>
                        </tbody>

                    </table>
                    </div>
                </div>
                </form>

this is the error that i am getting
numberFormatException:  null

空心化是控制器代码

private static void saveCountryDetails(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String countryname = request.getParameter(CountryConstant.COUNTRYNAME);
        String description = request.getParameter(CountryConstant.DESCRIPTION);

         //CountryDetail cd = new CountryDetail(); creates an instance to relate with the bean file CountryDetail.

        CountryDetail cd = new CountryDetail();
        cd.setCountryname(countryname);
        cd.setDescription(description);

        RouternHibernateConfigManager.persistObject(cd);

         // RequestDispatcher dispatches request to the desired page after inserting the data.

        RequestDispatcher requestDispatcher = request.getRequestDispatcher("jspfiles/countries.jsp");
        requestDispatcher.forward(request, response);

        // retriveCountryDetails(request, response);

    }

下面是bean文件代码

@Entity
@Table(name="COUNTRYDETAIL")
public class CountryDetail {
    @Id
    @Column(name = "CountryId", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer countryid;
    //@Lob
    //@Column(name = "COUNTRYFLAG" , columnDefinition ="mediumblob")
    //private byte[] countryFlag ;
    @Column(name = "CountryName", nullable = false)
    private String countryname;
    @Column(name = "Description", nullable = false , length = 2000)
    private String description;
    @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
    @JoinColumn(name="countryid")
    private List<StateDetail> stateDetails;

    /**
     * @return the stateDetails
     */

    public List<StateDetail> getStateDetails() {
        return stateDetails;
    }

    /**
     * @param stateDetails the stateDetails to set
     */
    public void setStateDetails(List<StateDetail> stateDetails) {
        this.stateDetails = stateDetails;
    }

    /**
     * @return the countryid
     */

    // @TableGenerator(name ="cid" , table ="ctab" , pkColumnName = "ckey" ,
    // pkColumnValue =" cvalue" , allocationSize =1)

    public Integer getCountryid() {
        return countryid;
    }

    /**
     * @param countryid
     *            the countryid to set
     */
    public void setCountryid(Integer countryid) {
        this.countryid = countryid;
    }

    /**
     * @return the countryname
     */

    public String getCountryname() {
        return countryname;
    }

    /**
     * @param countryname
     *            the countryname to set
     */
    public void setCountryname(String countryname) {
        this.countryname = countryname;
    }

    /**
     * @return the description
     */

    public String getDescription() {
        return description;
    }

    /**
     * @param description
     *            the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }





}

共 (0) 个答案