What does setting the header in JSP do?

Psyber

Senior member
Oct 27, 1999
677
0
0
I was going through a jsp tutorial on the web and ran across this:


response.setHeader("Location", "error.html");


The author says that this code forwards the page to error.html, but I found this not to be true. I was wondering if someone could give me an explanation on exactly what setting the header does in JSP.

Also, if someone could explain in simple words what "request" and "response" is in Java/JSP that would be great too. I tried googling but couldn't find an answer that made me truly understand these concepts (including the set header concept). If someone could give me an answer in layman's terms that would be great. Most of my Java is self-taught and I am still not clear on some terminology.

Thanks in advance,
Psyber
 

Aso

Senior member
Aug 16, 2000
381
0
76
Request is the HTTP request. Basically it is the incoming info to the page aka the Request
Response is the HTTP response. Basically this is the outgoing data.

The response and request objects are part of the HTTP protocol.
 

Psyber

Senior member
Oct 27, 1999
677
0
0
Originally posted by: Aso
Request is the HTTP request. Basically it is the incoming info to the page aka the Request
Response is the HTTP response. Basically this is the outgoing data.

The response and request objects are part of the HTTP protocol.

Thanks I did I bit more googling and I have a pretty good grasp of the concepts. I'm still not sure about what response.setHeader("Location", "error.html"); does though
 

manly

Lifer
Jan 25, 2000
12,979
3,742
136
I think the Location header is commonly known as an HTTP redirect. It's not common to set that header directly to forward control in JSPs; there are JSP directives to do that.

As for request and response, I wouldn't call them objects in the HTTP protocol. They're certainly central concepts in HTTP.

Think of HTTP as a ask & answer programming model. You send some info to the web server, which is wrapped up in the request object (by the servlet engine) so that you can manipulate it programmatically. Typically, an HTML page (or some alternative) is constructed to ship back to the client (browser). The response object (in the Servlets API) facilitates this construction in a variety of ways.

HTTP is generally a simple protocol to understand; you should read up on it to better under how to develop with servlets/JSP.