gpt4 book ai didi

java - 错误 : null value being entered in table through jsp code

转载 作者:行者123 更新时间:2023-11-28 22:56:48 25 4
gpt4 key购买 nike

我的代码片段如下:

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");
} %>

在上面的代码中,服务器在运行 ShopRegister3.jsp 后定向到 ShopMenu3.jsp然而在我的数据库中,正在为属性输入空值:名称、密码和位置。我已经尝试了很多东西...,到底哪里出错了?

最佳答案

您的 session 变量总是设置为空;使用:

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

在 session 中设置值之前获取值

关于java - 错误 : null value being entered in table through jsp code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25136860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com