Servlet匹配数据库中的值

时间:2015-10-08 10:42:12

标签: java jsp servlets codemirror

我尝试在读取我要将其标记为readOnly的值后从数据库中检索值,并使用CodeMirror的编辑器将其发送到我的jsp页面。

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        ArrayList<Exercise> exList = (ArrayList<Exercise>) request.getSession().getAttribute("exList");
        System.out.println("Retrieved exList of size: " + exList.size());
        String exerciseNum = request.getParameter("exNo");
        Exercise exercise = (Exercise) exList.get(Integer.parseInt(exerciseNum));

        PrintWriter pw = response.getWriter();
        pw.write("@questionText=" + exercise.getQuestionText());
        pw.write("@displayedCode=" + exercise.getDisplayedCode());
}

这是带有CodeMirror编辑器的jsp页面。

function submitSelectExercise(myDataString) {
                            $.ajax({
                                        type : "GET",
                                        url : "RetrieveSingleExerciseServlet",
                                        data : myDataString,
                                        success : function(result) {
                                            var pos = result
                                                    .indexOf("@displayedCode");
                                            if (pos > 0) {
                                                var questionText = result
                                                        .substring(14, pos - 1);
                                                var displayedCode = result
                                                        .substring(pos + 15,
                                                                result.length);
                                                $("#exQuestionText").empty()
                                                        .append(questionText);

                                                editor.getDoc().setValue(displayedCode);
                                            }
                                        }
                                    });
                            return false;
                        }

最终结果将是:

class DeclareVarInit {
    // declare constants 
    // DEDUCTION to be 2000 and 
    // TAX_RATE to be 0.2
    //**



    **//
    public static void main(String[] args) {
        // variables
        double incomeTax, taxableIncome, grossSalary;

        //declare numOfChildren and initialize to 2 
        //declare numOfParents and initialize to 2 


        int numOfDependents;

        // assignment statements
        grossSalary = 100000;
        numOfDependents = numOfChildren + numOfParents;
        taxableIncome = grossSalary - numOfDependents*DEDUCTION;
        incomeTax = taxableIncome * TAX_RATE;
        System.out.println("The income tax is " + incomeTax);
    }
  }

//****//之间,它将是可编辑的,其余部分将是不可编辑的。我之前从未学习过Servlets,而且我被这个项目抛弃了。

0 个答案:

没有答案