How to pass a value of a variable from a java class to the jsp page

后端 未结 3 384
傲寒
傲寒 2020-12-31 19:28

I have 2 files named Admin.java and index.jsp.

In Admin.java through a function I retrieve the value of the varible named

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 19:33

    If this is an ajax request, you can forward the request into another jsp page rather than return. With this

    getServletContext().getRequestDispatcher("/ajax.jsp").forward(request, response);
    
    create the jsp page(ajax.jsp) on your webcontent and add this sample code.
    
    

    ${rest}

    Another way is replace your System.out.println with this

    PrintWriter out = response.getWriter();
    out.print("The value of res been passed is "+res);
    

    but I guess this is a bad practice. See example here.

提交回复
热议问题