我在 send_quill_data.jsp 中创建了一个变量。下面的代码是send_quill_data.jsp。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Send data from one page to another</title>
<!-- Include Quill script -->
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<script src="https://cdn.quilljs.com/1.3.6/quill.image.js"></script>
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
<script>
var str = "";
function saveButton() {
str = quill.container.innerHTML;
console.log((str));
var xhr_vdata = new XMLHttpRequest();
if (xhr_vdata.readyState == XMLHttpRequest.DONE) {
parser = new DOMParser();
}
xhr_vdata.open("POST", "http://localhost:9999/report_generation_application/process_quill_data.jsp", true);
xhr_vdata.send('steps='+encodeURIComponent(str));
console.log("Data sent successfully");
}
</script>
</head>
<body>
<p><label class="l_str"><b>Steps to reproduce:</b></label></p>
<div id="editor-container"></div>
<script>
var quill = new Quill('#editor-container', {
modules: {
toolbar: [
// Include other toolbar options as needed
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
['bold', 'italic', 'underline'],
[{ 'list': 'ordered' }],
[{ 'list': 'bullet' }], // Add the 'bullet' list option
['image']
]
},
// Set other configurations as needed
theme: 'snow' // or 'bubble' theme
});
</script>
<button type="button" class="save" onclick="saveButton()">Save</button>
</body>
</html>
这里 process_quill_data.jsp 是我尝试向其发送数据的 jsp 页面。 process_quill_data.jsp 由以下服务器端代码组成,用于处理数据。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String steps_to_reproduce = request.getParameter("steps");
System.out.println(steps_to_reproduce);
%>
</body>
</html>
这里我无法打印鹅毛笔编辑器的内容,数据没有在服务器端读取。
问题出在您尝试使用
XMLHttpRequest()
调用的 JSP 中。 sriptlet 代码将不起作用,因为它会编译为 JSP 错误,并向调用者返回 500 状态代码。你看不到它是因为你还没有写回调错误函数。您应该检查服务器日志中是否有 JSP 错误。如果你想将内容写入响应并在成功回调函数中读取它,那么你可以使用
${param.str}