我是Web开发的新手。我的代码中有一个小问题。 这是我的JSP代码,无论我在文本框中输入什么值,它都将作为null存储在数据库中。请帮帮我。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<input type ="text" name ="movies">
<input type ="submit" name ="submit">
<% String rating = request.getParameter("submit");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shoppingmgmt","root","admin");
Statement st = con.createStatement();
int rs = st.executeUpdate("insert into movies values('"+rating+"')");
out.println("success");
}catch(Exception e){
out.println(e);
}
%>
</body>
答案 0 :(得分:2)
您是否尝试过调试代码?下一行将submit
按钮的值用作评分:
String rating = request.getParameter("submit")
...将其更改为以下内容以获取text
输入的值:
String rating = request.getParameter("movies")