Reputation: 6249
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
Reputation: 12696
Replace response.sendRedirect(...)
with:
RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.forward(request, response);
Upvotes: 3