I want to create a servlet class which receives two input parameters from a jsp let say login.jsp and thae servlet "CommandQueueTestServlet" set those incomming parameter as a header parameter and then send the request and response parameter to another servlet "CheckForCommandServlet".
I need to do this just to test my functionality because my "CheckForCommandServlet" will actually be invoked by some other application which has header parameter.
But for my own testing I want to create a servlet "CommandQueueTestServlet" for setting header.
Please check the below code what I am trying to explain
javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class CommandQueueTestServlet extends HttpServlet{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String hwId=request.getParameter("hardware_id");
String panelistId=request.getParameter("panelist_id"));
// Setting input parameter as header parameter.Since request object dont have setHeader so setting in response
//object
response.setHeader("x-HwId",hwid);
response.setHeader("x-panelistId,panelistId);
// creating instance of CheckForCommandServlet and passing in doGet() method:
CheckForCommandServlet headerParam= new CheckForCommandServlet();
headerParam.doGet(request,response);
}
}
// Code for CheckForCommandServlet
public class CheckForCommandServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Enumeration enumeration = httpServletRequest.getHeaderNames();
String headerName;
String headerValue;
while (enumeration.hasMoreElements())
{
headerName = (String)enumeration.nextElement();
if (headerName == null)
{
headerName = "";
}
headerName = headerName.toLowerCase();
headerValue = httpServletRequest.getHeader(headerName);
logger.log(Level.INFO, "Header headerName " + headerName);
logger.log(Level.INFO, "Header ParamaterValue " + headerValue);
}
}
How did my CheckForCommandServlet get the headerParemeter set in CommandQueueTestServlet as it is set in header parameter.