Allons. 2019-05-10 02:02 采纳率: 0%
浏览 304

在调用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>

  • 写回答

5条回答 默认 最新

  • ꧁gaoKuo꧂ 2019-05-10 09:08
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题