package request;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//request请求转发,以及使用request域对象吧数据带给转发资源
public class RequestDemo5 extends HttpServlet {
//用congtext存数据是行不通的,但是request存数据是可以的,每个请求对象都有唯一的request
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String data = "aaaaaa";
request.setAttribute("data", data);
//request也可实现转发
request.getRequestDispatcher("/message.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
request 请求转发