Java Server Pages - Request Object
Java (current. Jakarta) Server Pages is a framework used for web application development.
This post will discuss:
- Request Object and Methods
Request Object
The request object in JSP is used for:
- Reading info from the client
- Letting the server read info
- Reading parameters from a client request
- Reading the data on cookies
In other words, it deals with the interactions between a client and its server.
These are more general methods:
Methods for request object:
getContextPath()
Gets the path for the request object.
setMethod();
Sets the method by which the request is communicated.
getServerName():
Gets server name.
getServerPort();
Gets port number.
getRequestURL/URI()
Gets server URL.
getRemoteAddr();
Gets remote address.
getProtocol();
Gets the protocol used. (Between client, server)
The essential methods for the request object, however, are those that handle data communicated over pages by the request object:
Methods for request object:
getParameter():
Gets the parameters passed by the request, by key/name.
getParameterValues():
Gets all values passed by the request.
getParameterNames():
Gets all keys in enum.
getParameterMap():
Gets map object. Contains the keys and corresponding values.
The request object is called from inside the document. The input field must specify the name and type values.
<form action="recipient_page.jsp" method="get/post"></form>
And can then be handled. The value of the request is saved to the defined variable.
String a = request.getParameter("abc");
-gonkgonk