JSP and the Request & Response Objects
The response object in JSP is an implicit object. This means it is used so frequently, it is automatically available without instantiation by Tomcat.[1] This object is used frequently to access user input information.
Variables in HTML are often given a ‘name’ attribute to interact with in Java or other languages like CSS or in our case, JSP. The JSP request object can access these as well. Beginner’s Book provides an example of a sign-in page. In their index.html file, they redirect control to a JSP file when the form is submitted.
To get the information entered by the user, we can use request.getParameter(“html_name_attribute”); inside the scriptlet tag. This can be used to check the values against the ones stored to determine access.
The request object also has many functions we can use to get information, make changes, and process the request. This list is on Beginner’sBook, but below are my brief descriptions of the methods.[2]
void setContentType(String type)…………………………..
If the request produces something different than the
original content, it can be changed.
void sendRedirect(String address)…………………………
send the user somewhere when this line occurs.
void addHeader(String name, String value)…………….
add an HTML header.
void setHeader(String name, String value)………………
change the HTML header.
boolean containsHeader(String name)…………………..
checks for a header.
void addCookie(Cookie value)………………………………
add some information to the response.
void sendError(int status_code, String message)………
Think 404- Page not found, but what you show the client/browser.
boolean isCommitted()………………………………………..
This checks if the response has been sent to the
client/browser yet. Yes/true or No/false.
void setStatus(int statuscode)………………………………
Also think error 404, page not found. This sets the internal error status.
Beginning Jakarta EE Web Development: Using JSP, JSF, MySQL, and Apache Tomcat for Building Java Web Applications 3rd ed., Luciano Manelli , Giulio Zambon, Ch. 2.
https://beginnersbook.com/2013/11/jsp-implicit-object-response-with-examples/