I am trying to hand over a text from a textarea. After serveral actions I want to return the result and print the result in another textarea.
First my index.jsp: The first textarea codeEditor
has the text. Aftler clicking the button analysisButton
the 2nd textarea commentBox
should fill.
<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>
Then my index.js: Here I am trying to use AJAX like in the first answer of this question
$('body').on('click', '#analysisButton', function(){
$.get("AnalysisServlet",function(responseText){
$("#commentBox").text(responseText);
});
});
and at least my servlet where I call my 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);
}
I am getting a NullPointerException while I am trying to set the variable sql
in my MainVisitor
EDITED:
I think my problem is that I didn't read the content of codeEditor
I added now var sql = $("#codeEditor").val();
to my JS but I don't have an idea how to proceed