Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 错误:通过jsp代码在表中输入空值_Java_Mysql_Jsp_Tomcat_Database Connection - Fatal编程技术网

Java 错误:通过jsp代码在表中输入空值

Java 错误:通过jsp代码在表中输入空值,java,mysql,jsp,tomcat,database-connection,Java,Mysql,Jsp,Tomcat,Database Connection,我的代码片段如下所示: ShopRegister2.jsp: <% session = request.getSession(); session.setAttribute("s_id", s_id); out.println("Your id is : "+s_id); %> <br> Please note it for further use.!<br> <for

我的代码片段如下所示:

ShopRegister2.jsp:

<% 
session = request.getSession();
session.setAttribute("s_id", s_id);
out.println("Your id is : "+s_id);
        %>          
        <br>
        Please note it for further use.!<br>
        <form name="register" method="post" onsubmit=" return reg_form()"     action="ShopRegister3.jsp"><br>
        Enter your name : <input type="text" name="s_name" id="s_name"><br>
        Enter your Location : <input type="text" name="s_location" id="s_location"><br>
        Enter your password : <input type="password" name="s_password" id="s_password">    <br>
        Confirm Password : <input type="password" name="c_s_password"     id="c_s_password"><br>
        <input type="submit" value="Submit"><br>
        </form><br>


请记下以备将来使用

输入您的姓名:
输入您的位置:
输入您的密码:
确认密码:


ShopRegister3.jsp:

String s_name=null, s_password=null, s_location=null;
int s_id = 0;   

session.setAttribute("s_name", s_name);
session.setAttribute("s_password", s_password);  
session.setAttribute("s_location", s_location);

String s_id_string=(String)request.getParameter("s_id");
s_id = session.getAttribute("s_id") != null ? (Integer) session.getAttribute("s_id") : 0 ;          
s_name=(String)session.getAttribute("s_name");
s_password=(String)session.getAttribute("s_password");
s_location=(String)session.getAttribute("s_location");

//entering values into Shop table
PreparedStatement s_insert = con.prepareStatement("insert into ShopSystem.Shop values(?,?,?,?)");
s_insert.setInt(1, s_id);
s_insert.setString(2, s_password);                  
s_insert.setString(3, s_location);
s_insert.setString(4, s_name);
int c = s_insert.executeUpdate();
//checking whether the value was inserted successfully
if(c>0)
{    %>
S_ID = <%= s_id %> has been registered successfully.<br>
<%  response.sendRedirect("ShopMenu3.jsp");     
} %>
字符串s_name=null,s_password=null,s_location=null;
int s_id=0;
setAttribute(“s_名称”,s_名称);
session.setAttribute(“s_密码”,s_密码);
session.setAttribute(“s_位置”,s_位置);
字符串s_id_String=(String)request.getParameter(“s_id”);
s_id=session.getAttribute(“s_id”)!=无效的(整数)session.getAttribute(“s_id”):0;
s_name=(String)session.getAttribute(“s_name”);
s_密码=(字符串)session.getAttribute(“s_密码”);
s_位置=(字符串)session.getAttribute(“s_位置”);
//将值输入到Shop表中
PreparedStatement s_insert=con.prepareStatement(“插入到ShopSystem.Shop值(?,?,?)”;
s_insert.setInt(1,s_id);
s_insert.setString(2,s_密码);
s_插入设置管柱(3,s_位置);
s_insert.setString(4,s_名称);
int c=s_insert.executeUpdate();
//正在检查值是否已成功插入
如果(c>0)
{    %>
S_ID=已成功注册。
在上面的代码中,服务器在运行ShopRegister3.jsp后指向ShopMenu3.jsp 然而,在我的数据库中,为属性输入了空值:名称、密码和位置。
我试过很多东西,到底哪里出了问题?

也许这就是问题所在

String s_name=null, s_password=null, s_location=null;

然后将会话设置为空值。

会话变量始终设置为空值; 使用:

在会话中设置值之前获取这些值

s_name=(String)request.getParameter("s_name");
s_password=(String)request.getParameter("s_password");
s_location=(String)request.getParameter("s_location");