我在JSP表单页面中有一个URL链接。提交表单后,所有数据都将提交并调用URL链接。如何将我提交给URL链接的数据转发到另一个JSP页面。
的index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>JSP Page</title>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
function response() {
$.ajax({
url : "http://xxxxx/sendmsg",
data : {
"username" : msg_user,
"recipient" : msg_recipient,
"sender" : msg_sender,
"content" : msg_content
},
success : function(data) {
$('#ajaxgetUserServletResponse').text(responseText);
},
error: function(data, err) {
console.error(err);
}
});
}
</script>
</head>
<body>
<form action="http://xxxxx/sendmsg" method="post" target="_blank">
<input name=" msg_user" type="text"/><br>
<input name="msg_recipient" type="text"/><br>
<input name="msg_sender" type="text"/><br>
<input name="msg_content" type="text"/><br>
<button type="submit" style="display: none;">SUBMIT</button>
</form>
<br/>
<hr/>
</body>
我可以提交表单并致电URL链接。但不幸的是,只有我们之前提交的表格细节没有显示成功的消息回复。
是否有人能够提供我的指南,我应该如何继续或继续?
答案 0 :(得分:0)
我还没有对此进行测试,但我觉得值得尝试。
function response() {
$.ajax({
var msg_user = $('form input[name=msg_user]').val();
var msg_recipient = $('form input[name=msg_recipient]').val();
var msg_sender = $('form input[name=msg_sender]').val();
var msg_content = $('form input[name=msg_content]').val();
url: "http://xxxxx/sendmsg",
data: {
"username": msg_user,
"recipient": msg_recipient,
"sender": msg_sender,
"content": msg_content
},
success: function(data) {
var response = "Username: " + msg_user + "<br>" +
"Recipient: " + msg_recipient + "<br>" +
"Sender:" + msg_sender + "<br>" +
"Content: " + msg_content;
$('#ajaxgetUserServletResponse').text(response);
},
error: function(data, err) {
console.error(err);
}
});
}
&#13;