Hey Guys,
This is the scenario... I need to set a value in the HTTP headers which are sent from the browser, i.e the
JSP and need to retrieve that value in a
servlet using getHeader() or an equivalent. For eg, I need to send a value like the username in the header and then retrieve the same in the servlet. I'm currently using the URLConnection class' addRequestProperty(
String key, String value) to set the value and then retrieve it in the servlet using request.getHeader(). But it is returning null all the time.. plzzzz do let me know about the issue. The code is below.
JSP code :
<%URL url = new URL
http://localhost:9090/MMPortal/servlet/ShowRequestHeaders"); URLConnection conn = url.openConnection();
conn.setAllowUserInteraction(false);
conn.setDoOutput(true);
conn.setRequestProperty("UserID","Abhishek");
%>
Servlet Code :
request.getHeader("UserID"); inside the doGet() method.
Please do advice on this. Thanks in advance.