1

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>

1 Answer 1

3

Replace response.sendRedirect(...) with:

RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.forward(request, response);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.