我想将所有打包到summernote富文本编辑器中的内容返回给servlet,这样我就可以将它保存到数据库中,但我无法知道如何操作。
我的jsp页面脚本:
<script>
$(document).ready(function()
{
$('#summernote').summernote();
});
</script>
<script type="text/javascript">
var markupStr = $('#summernote').summernote('code'); //this gets the contents from the text editor.
function myFunction()
{
return markupStr = $('#summernote').summernote('code');
}
</script>
在jsp中按钮提交给servlet:
新内容: 这里的Servlet
String test = request.getParameter("summerNoteText");
答案 0 :(得分:0)
实际问题应该是:
如何设置文本值和表单元素?
如何将其提交给服务器?
答案:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>add text to text area and submit</title>
<!-- include libraries(jQuery, bootstrap) -->
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<!-- include summernote css/js-->
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.js"></script>
<body>
<div id="summernote">Hello Summernote</div>
<script>
$(document).ready(function() {
$('#summernote').summernote();
// copy the html-text from summernote to the hidden textarea
// and let the browser submit it
$('#myForm').submit(function() {
$('textarea[name=summerNoteText]').val($('#summernote').summernote('code'));
});
});
</script>
<!-- use method post, because method get has limits of the max length -->
<form action="Test" method="post" id="myForm">
<!-- add a hidden textarea, wher the summernote code will be writen on submit -->
<textarea name="summerNoteText" style="display:none;"></textarea>
<input type="submit"/>
</form>
</body>
</html>
说明: