JSP - 更新当前页面

时间:2016-02-19 11:56:01

标签: java jsp servlets

我有一个jsp页面,我可以打开一些代码。我实现了一个分析开放代码的函数。

我目前的情况:

在我的wd <- getwd() cprof <- getChromeProfile(wd, "Profile 1") remDr <- remoteDriver(browserName= "chrome", extraCapabilities = cprof) 我有index.jspcodeEditor

button

我的servlet只有一个<form action="AnalysisServlet" method="post" target="_blank"> <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> <div class="analysisButton"> <button type="submit" id="startAnalysis" class="btn btn-default btn-block" style="margin-top: 10px;">Start analysis</button> </div> </form> 方法

doPost

我的分析结果将显示在一个新的jsp

protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { 
    // create bean
    MainVisitor mainVisitor = new MainVisitor();
    request.setAttribute("mainVisitor", mainVisitor);

    // get SQL from index.jsp
    mainVisitor.setSql(request.getParameter("codeEditor"));

    request.getSession().setAttribute("analysisAttr", mainVisitor);
    request.getServletContext().getRequestDispatcher("/analysis.jsp").forward(request, response);
}   

我的问题:我需要留在<textarea name="codeEditor" class="form-control" id="codeEditor" rows="15" style="resize: none;">${sessionScope.analysisAttr.result}</textarea> 并更新/展开index.jsp

这可能没有ajax吗?我对ajax一无所知所以如果我能留在我的jsp,servelt,java contex中它会很棒:/

谢谢:)

1 个答案:

答案 0 :(得分:0)

这是我的解决方案:

我删除了表单并添加了:

$('body').on('click', '#analysisButton', function(){
    $.get("AnalysisServlet",function(responseText){
        $("#commentBox").text(responseText);
    });
});
相关问题