在调用rquest.getParameter中遇到了问题

在调用rquest.getParameter中遇到了问题
调用的是String类型
但是我需要的是Integer型
于是我用int sid = Integer.parseInt(request.getParameter("sid"));将其转换
但是运行时报错
显示就是这行的错误图片说明

这个是registerFunction.jsp

<%@ include file="inc.jsp" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import = "java.lang.*" %>

<%
String lId = request.getParameter("lId");
String lPassword = request.getParameter("lPassword");
String confirmPassword = request.getParameter("confirmPassword");
int sid = Integer.parseInt(request.getParameter("sid"));
if(!(confirmPassword.equals(lPassword))){
    out.println("两次输入的密码不同");
    out.println(confirmPassword);
    out.println(lPassword);
}
 else{
    String sql = "insert into login values('" + lId +"','" +lPassword + "'," + sid + ");";
    try{
          Class.forName(driver).newInstance();
          Connection conn = DriverManager.getConnection(url, user,password);
          Statement stm = conn.createStatement();
          ResultSet rs = stm.executeQuery(sql);}
    catch(Exception e){
          e.printStackTrace();
          out.println(e);}
}
%>

下面是register.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .p{
            color:red;
            margin-left:20px;
            display:inline-block;
        }
        .c{
            color:red;
            margin-left:4px;
            display:inline-block;
        }
        .l{
            font-size:18px;
        }
        .d{
            height:35px;
            width:300px;
            display:inline;
        }
        .i{
            height:30px;
            width:300px;
        }
        .position{position:absolute;
               top:50%;
               left:50%;
               transform:translate(-50%,-50%);}
    </style>
</head>
<body>
    <div style="height:80px;"></div>
    <form class = "position" action = "registerFunction.jsp" method = "post">
        <div style="width:500px;float:left;margin:0 20px;">
            <div style="font-size:28px;position:absolute;left:50%; transform:translate(-50%,-50%);">注册新用户</div>
            <br/>
            <span class="p">*</span>
            <label for="username" class="l">用户名:</label>
            <div style="height:35px;width:300px;position:relative;display:inline;">
                <input name="lId" type="text" style="height:30px;width:250px;padding-right:50px;">
                <span style="position:absolute;right:18px;top:2px;background-image:url(user.ico);height:16px;width:16px;display:inline-block;" ></span>
            </div>
            <br/><br/>
            <span class="c">*</span>
            <label for="login_password" class="l">登录密码:</label>
            <div  class="d">
                <input name="lPassword" type = "password" class="i" maxlength = "15" required >
            </div>
            <br/><br/>
            <span class="c">*</span>
            <label for="confirmPassword" class="l">确认密码:</label>
            <div  class="d">
                <input name="confirmPassword" type="password" class="i" required >
            </div>
            <br/><br/>
            <span class="p">*</span>
            <label for="sid" class="l">学生号:</label>
            <div  class="d">
                <input id="sid" type="text" class="i" onkeyup="value=value.replace(/[^\d]/g,'')" placeholder = "请输入您的十位数学号">
            </div>
            <br/><br/>
            <input type="submit" value="注册" style="margin-left:100px;height:30px;width:300px;background-color:blue;display:inline-block;"/>

        </div>
    </form>

</body>
</html>

request.getParameter("sid")这个的结果为null

request.getParameter("sid")为null,加一个空判断就好了,为空就给一个默认值

int sid = 0;
String sid_string = request.getParameter("sid");
if(sid_string!=null||sid_string!='') sid = Interger.parseInt(sid_string);

request.getParameter("sid")这个的结果为null,对bull做parseInt转化就会发生如上错误。

转换的时候参数为空,加一个是否为空的判断

你这个错误是表示你这个request里的sid为null,所以转换时回报错,要么接受错了也就是sid在你上一个页面没有,又或者你上一个页面没有跳到这个页面上