1 / 22

Forms - Java Server Pages

Forms - Java Server Pages. request is an implicit object that we use for retrieving form information request is an instance of class HttpServletRequest Information can be found at http://java.sun.com/webservices/docs/1.5/api/javax/servlet/http/HttpServletRequest.html.

aria
Download Presentation

Forms - Java Server Pages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Forms - Java Server Pages • request is an implicit object that we use for retrieving form information • request is an instance of class HttpServletRequest • Information can be found at http://java.sun.com/webservices/docs/1.5/api/javax/servlet/http/HttpServletRequest.html

  2. Forms - Java Server Pages • The HttpServletRequest interface has some important methods • getMethod( )          Returns the name of the HTTP method with which this request was made, for example, GET, or POST. • Returns a String

  3. Forms - Java Server Pages • To retrieve the method used: • The method is: • <%= request.getMethod( ) %>

  4. HttpServletRequest methods • getQueryString( )          Returns the query string that is contained in the request URL after the path. • Returns a String

  5. Forms - Java Server Pages • To retrieve the query string: • The query string is: • <%= request.getQueryString( ) %>

  6. HttpServletRequest methods • getRemoteUser()          Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated. • Return a String

  7. Forms - Java Server Pages • To retrieve the remote user: • The remote user is: • <%= request.getRemoteUser( ) %>

  8. HttpServletRequest methods • getCookies()          Returns an array containing all of the Cookie objects the client sent with this request. • Returns an array of Cookie objects • Cookie is a class

  9. HttpServletRequest methods • getSession()          Returns the current session associated with this request, or if the request does not have a session, creates one. • Returns an HttpSession object • HttpSession is a class

  10. HttpServletRequest methods • HttpServletRequest extends the interface ServletRequest and inherits its methods • getRemoteAddr()          Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.  Returns a String • getRemoteHost()          Returns the fully qualified name of the client or the last proxy that sent the request. Returns a String

  11. Forms - Java Server Pages • To retrieve the remote address and the remote host: • The remote address is: • <%= request.getRemoteAddr( ) %> • The remote host is: • <%= request.getRemoteHost( ) %>

  12. HttpServletRequest methods • isSecure()          Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. Returns a boolean. • getLocalPort()          Returns the Internet Protocol (IP) port number of the interface on which the request was received. Returns an int.

  13. Forms - Java Server Pages • To retrieve if the connection is secure and the local port: • Is the connection secure? • <%= request.isSecure( ) %> • The local port is: • <%= request.getLocalPort( ) %>

  14. HttpServletRequest methods • getContentLength()           Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known. Returns an int.

  15. Forms - Java Server Pages • To retrieve the number of bytes from user input • The number of bytes to read is: • <%= request.getContentLength( ) %>

  16. HttpServletRequest methods • getContentLength()           Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known. Returns an int. • getInputStream()           Retrieves the body of the request as binary data using a ServletInputStream. Returns a ServletInputStream.

  17. HttpServletRequest methods •  To retrieve user input • getParameter(String name)           Returns the value of the named attribute as an Object, or null if no attribute of the given name exists. Returns an Object. • getAttributeNames()           Returns an Enumeration containing the names of the attributes available to this request. Returns an Enumeration.

  18. HttpServletRequest methods • getAttributeNames()           Returns an Enumeration containing the names of the attributes available to this request. Returns an Enumeration. • Also getParameterNames( ), also return an Enumeration

  19. Forms - Java Server Pages • To retrieve the data entered by the user for the object named “id” • The data entered is: • <%= request.getParameter( “id” ) %>

  20. Forms - Java Server Pages • To retrieve all the parameters (names of the objects) of the form • <% • Enumeration enu = • request.getParameterNames( ); • // Process enu here (use a loop) • %>

  21. Forms - Java Server Pages • // enu is the Enumeration from before • String attName = “”; • String data = “”; • while( enu.hasMoreElements( ) ) • { • attName = (String) enu.nextElement( ); • out.print( attName + ": " ); • data = request.getParameter( attName ); • out.println( data ); • }

  22. Forms - Java Server Pages • For checkboxes, you can use the getParameterValues method • It returns an array of Strings • You can then process that array with a for loop • Be careful, the array could be null if no checkbox has been selected by the user

More Related