gpt4 book ai didi

java - post 方法不适用于 postman (chrome 扩展)

转载 作者:行者123 更新时间:2023-11-29 13:13:38 24 4
gpt4 key购买 nike

我有一个项目,在这个项目中,我只是将两个值保存到mysql数据库中,它工作正常。我的要求是我想使用 postman 发送数据,但这些值没有保存到数据库中,我没有得到任何异常,请帮助我如何解决这个问题。我的代码是:

主页.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function validateForm()
{
var x=document.getElementById("location").value;
if( x == "" )
{
alert( "Please Enter The Location!" );

return false;
}
var y=document.getElementById("time").value;
if( y == "" )
{
alert( "Please Enter The Time!" );

return false;
}
var digits = "0123456789";
var temp;

for (var i = 0; i < document.getElementById("time").value.length; i++) {
temp = document.getElementById("time").value.substring(i, i + 1);
if (digits.indexOf(temp) == -1) {
alert("Please enter correct time");
document.getElementById("time").focus();
return false;
}
}
}
</script>
</head>
<body bgcolor="cyan">
<form name="myForm" method="post" action="insert.jsp" onsubmit="return validateForm()">
<div style="background-image:url(bg.jpg);">
<center><h1><font color="red">TRAFFIC INFORMATION SYSTEM</font></h1></center><br>
</div>
<hr size="10" color="red">
<center>
<table cellpadding="12">
<tr>
<td align="left">
Location</td><td> <input type="text" name="location"></td>
<tr>
<td align="right">
Expected Time
</td>
<td align="left">
<input type="text" size="3" name="time" maxlength="3">
Minutes
</td>
</tr>
<tr><td></td>
<td><input type="image" src="submit.gif" alt="Submit" width="48" height="48"/></td></tr>
</table>
</center>
</form>
</body>
</html>

插入.jsp

<%
DBCreation creation;
Connection connection;
String location;
String time;

location=request.getParameter("location");
time=request.getParameter("time");

connection=new DBCreation().getConnection();

try {
PreparedStatement statement=connection.prepareStatement("insert into Jam_Info values(?,?)");
statement.setString(1, location);
statement.setString(2, time);
int i=statement.executeUpdate();
if(i>0)
{
RequestDispatcher dispatcher=request.getRequestDispatcher("success.jsp");
dispatcher.forward(request, response);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

%>

最佳答案

您必须编写提交来保存数据

connection.commit(); 

您尚未关闭连接。

connection.close();

将其写入 Final block 中。

关于java - post 方法不适用于 postman (chrome 扩展),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21773527/

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