Java HTTP状态500-字符串到整数转换时发生异常

Java HTTP状态500-字符串到整数转换时发生异常,java,mysql,eclipse,jsp,amazon-rds,Java,Mysql,Eclipse,Jsp,Amazon Rds,环境:我在EclipseKepler工作,我的MySQL数据库在AWS RDS上。我的目标是创建一个基于web的项目,因此我的项目是“AWS Java web项目”。另外,对于数据库连接,我已经将mysql连接器-*-bin.jar文件添加到我的构建路径中 下面的代码当我作为一个简单的java应用程序运行时,它运行良好,但当我在Tomcat服务器上运行它时,它会显示以下错误: org.apache.jasper.JasperException:在第114行处理JSP页面/WelcomeCusto

环境:我在EclipseKepler工作,我的MySQL数据库在AWS RDS上。我的目标是创建一个基于web的项目,因此我的项目是“AWS Java web项目”。另外,对于数据库连接,我已经将mysql连接器-*-bin.jar文件添加到我的构建路径中

下面的代码当我作为一个简单的java应用程序运行时,它运行良好,但当我在Tomcat服务器上运行它时,它会显示以下错误:

org.apache.jasper.JasperException:在第114行处理JSP页面/WelcomeCustomer.JSP时发生异常

第114行:

     String s_id_string=(String)request.getParameter("s_id");       
    int s_id = Integer.parseInt(s_id_string);
根本原因

java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
org.apache.jsp.WelcomeCustomer_jsp._jspService(WelcomeCustomer_jsp.java:180)
第180行:

o_insert.setString(4, Cust_contact_string);
注:客户联系人字符串为字符串类型

请帮助我,我似乎已经克服了这个错误

提前谢谢

更新:

<form name="s_id_form" method="post" onsubmit=" return s_id_form()"> 
Choose a Shop from above by entering the respective s_id : 
<input type="text" name="s_id" id="s_id"> <input type="submit" value="submit"> 
</form>     
<%  
String s_id_string=(String)request.getParameter("s_id");    
int s_id = Integer.parseInt(s_id_string);   
%> 

通过输入相应的s_id,从上面选择一家店铺:

不要信任客户端验证。还要始终放置服务器端验证

对于提供的输入(
null
)来说,异常是显而易见的

继续之前,请检查
null
。以及检查是否存在

在提供的检查之后,请在
中包装您的代码,并尝试catch block
在奇怪的输入传递到服务器端时执行某些操作

处理JSP页面时发生异常
/WelcomeCustomer.JSP

我建议你避免涂鸦和使用,避免这样的错误

${param.s_id}

阅读更多关于

param:
将请求参数名称映射到单个值


您可以为此使用or来检查
null
empty

<c:if test="${empty param.s_id}">
    s_id is empty or null.
</c:if>
<c:if test="${not empty var1}">
    s_id is NOT empty or null.
</c:if>

s_id为空或空。
s_id不为空或null。


s_id为空或空。
s_id不为空或null。
${notempty param.s_id}
也可以通过
${!empty param.s_id}
完成


发生这种情况是因为
s\u id\u string
null
。请将代码修改为

String s_id_string=(String)request.getParameter("s_id");       
int s_id=0;
if(s_id_string !=null || s_id_string !=""){
  s_id = Integer.parseInt(s_id_string);
}
else{
  s_id=0;//assign any value
}

为了获得更多参考,我粘贴了整个代码:不能将null解析为数字。因此,在转换(解析)之前确保是否为null。是的,我正在通过如下javascript代码检查它是否为null:函数s_id_form(){var s_id=document.s_id_form.s_id;if(s_id.value==“”){window.alert(“输入店铺id!”);return false;}return true;}不要将代码作为注释发布,而是用它们更新您的帖子。感谢它起到了作用。很抱歉,我还没有足够的声誉来提升您的声誉。我会及时更新您的帖子。…)
String s_id_string=(String)request.getParameter("s_id");       
int s_id=0;
if(s_id_string !=null || s_id_string !=""){
  s_id = Integer.parseInt(s_id_string);
}
else{
  s_id=0;//assign any value
}