InfoCenter Home >
3: Migration overview >
3.3: Migrating APIs and specifications >
3.3.2: Migrating to supported Servlet specification and extensions >
3.3.2.1: Example: Migrating HttpServiceResponse.callPage()

3.3.2.1: Example: Migrating HttpServiceResponse.callPage()

Calls to HttpServiceResponse.callPage() need to be replaced by calls to RequestDispatcher, as shown.

Before -- Using HttpServiceResponse.callPage()

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class UpdateJSPTest extends HttpServlet
{
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String message = "This is a test";
((com.sun.server.http.HttpServiceRequest)req).setAttribute("message", message);
((com.sun.server.http.HttpServiceResponse)res).callPage("/Update.jsp", req);
}
}

After -- Using RequestDispatcher

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class UpdateJSPTest extends HttpServlet
{
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String message = "This is a test";
req.setAttribute("message", message);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/Update.jsp");
rd.forward(req, res);
//((com.sun.server.http.HttpServiceRequest)req).setAttribute("message", message);
//((com.sun.server.http.HttpServiceResponse)res).callPage("/Update.jsp", req);
}
}

Go to previous article: Migrating to supported Servlet specification and extensions Go to next article: New Servlet Engine option for migrating applications to Servlet 2.2

 

 
Go to previous article: Migrating to supported Servlet specification and extensions Go to next article: New Servlet Engine option for migrating applications to Servlet 2.2