简体   繁体   English

为什么从表单提交中为我的JSP代码段提供了空值?

[英]Why is a null value provided to my JSP snippet from the form submission?

Hi I wish to get a users age from a form and convert that String to an int and use elsewhere in a java class 嗨,我希望从表单中获得用户的年龄并将该String转换为int并在java类的其他地方使用

The .jsp snippet looks like this .jsp片段如下所示

    <% 
    String str = request.getParameter("age"); 
    int convertInt = Integer.parseInt(str); 
    %>

    <% myProgram.comAvgerage(convertInt);%>

however i am getting HTTP Status 500 - java.lang.NumberFormatException: null 但是我正在获取HTTP Status 500-java.lang.NumberFormatException:null

I think this is because the form is being created in a UI class first thus the fields are null ? 我认为这是因为表单是首先在UI类中创建的,因此字段为null?

Is this the fault and can i fix this thanks 这是故障吗,我可以解决这个问题吗?

This suggests that request.getParameter("age") is returning null. 这表明request.getParameter(“ age”)返回null。 This means that there is no parameter called "age" being submitted via the form. 这意味着不会通过表单提交名为“ age”的参数。 Check to make sure "age" is the name of your form parameter. 检查以确保“ age”是表单参数的名称。 ie. 即。 input type="text" id="parameter" name=" age " value="test" 输入type =“ text” id =“ parameter” name =“ 年龄 ” value =“ test”

They must match make sure the cases match too. 它们必须匹配,以确保大小写也匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM