【发布时间】:2016-06-08 07:48:24
【问题描述】:
我正在尝试从 textarea 交出文本。经过几次操作后,我想返回结果并在另一个文本区域中打印结果。
首先我的 index.jsp:第一个 textarea codeEditor 有文本。单击按钮analysisButton 后,第二个文本区域commentBox 应该会填充。
<div class="form-group">
<label for="codeEditor" style="margin-top: 15px;">Code:</label>
<textarea name="codeEditor" class="form-control" id="codeEditor" rows="15" style="resize: none;"></textarea>
</div>
<button id="analysisButton" class="btn btn-default btn-block" style="margin-top: 10px;">Start analysis</button>
<div class="form-group">
<label for="comment" style="margin-top: 15px;">Comment:</label>
<textarea class="form-control" id="commentBox" style="resize: none;height:330px;"></textarea>
</div>
然后是我的 index.js:在这里我尝试使用 AJAX,就像在这个 question 的第一个答案中一样
$('body').on('click', '#analysisButton', function(){
$.get("AnalysisServlet",function(responseText){
$("#commentBox").text(responseText);
});
});
至少是我的 servlet,我称之为我的 bean
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
MainVisitor mainVisitor = new MainVisitor();
request.setAttribute("mainVisitor", mainVisitor);
mainVisitor.setSql(request.getParameter("codeEditor"));
String result = mainVisitor.getResult();
resp.setContentType("text/html");
resp.setCharacterEncoding("UTF-8");
resp.getWriter().write(result);
}
当我尝试在我的 MainVisitor 中设置变量 sql 时遇到 NullPointerException
编辑:
我想我的问题是我没有看codeEditor的内容
我现在将 var sql = $("#codeEditor").val(); 添加到我的 JS,但我不知道如何继续
【问题讨论】:
标签: javascript jquery ajax jsp servlets