user595234
user595234

Reputation: 6249

how to put the object to Java servlet response?

In a Java servlet, how might I put the object to servlet response? In the code below, the name is shown on the page.

servlet:
private void process(HttpServletRequest request, HttpServletResponse response) throws Exception{
        String name = "John";
        System.out.println("main servlet");
        request.setAttribute("name", name);
        response.sendRedirect("index.jsp");     
    }

index.jsp in JSTL
<body>
name: ${requestScope.name}
</body>

Upvotes: 1

Views: 2093

Answers (1)

wannik
wannik

Reputation: 12696

Replace response.sendRedirect(...) with:

RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.forward(request, response);

Upvotes: 3

Related Questions