Create new HttpServletRequest object in Servlet
Sometimes you not need to use default object of HttpServletRequest in Servlet, you need to create new object of HttpServletRequest, in this situation you can use listed below code to create new object of HttpServletRequest. in this code just use default object " request" of HttpServletRequest in "doPost" or "doGet" method.
public void doPost(HttpServletRequest request, HttpServletResponse res)
throws IOException, ServletException {
HttpServletRequest hsr = (HttpServletRequest) request;
// now use hsr
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void doGet(HttpServletRequest request, HttpServletResponse res)
throws IOException, ServletException {
HttpServletRequest hsr = (HttpServletRequest) request;
// now use hsr
}
Sometimes you not need to use default object of HttpServletRequest in Servlet, you need to create new object of HttpServletRequest, in this situation you can use listed below code to create new object of HttpServletRequest. in this code just use default object " request" of HttpServletRequest in "doPost" or "doGet" method.
public void doPost(HttpServletRequest request, HttpServletResponse res)
throws IOException, ServletException {
HttpServletRequest hsr = (HttpServletRequest) request;
// now use hsr
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void doGet(HttpServletRequest request, HttpServletResponse res)
throws IOException, ServletException {
HttpServletRequest hsr = (HttpServletRequest) request;
// now use hsr
}