Form processing with Servlets - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Form processing with Servlets

Description:

POST method process form data inside doPost method ... servlet-name processForm /servlet-name url-pattern /go /url-pattern /servlet-mapping ... – PowerPoint PPT presentation

Number of Views:74
Avg rating:3.0/5.0
Slides: 7
Provided by: julie387
Category:

less

Transcript and Presenter's Notes

Title: Form processing with Servlets


1
Form processing with Servlets
  • GET method ? process form data inside doGet
    method
  • POST method ? process form data inside doPost
    method
  • The doPost method takes the same parameters as
    the doGet method

2
Servlet doPost method
  • The doPost method header is
  • public void doPost( HttpServletRequest request,
  • HttpServletResponse response)
  • throws IOException,

  • ServletException
  • ? We have access to the HttpServletRequest and
    HttpServletResponse parameters (remember the 2
    implicit objects request and response in JSPs)

3
doGet and doPost methods
  • One method can call the other in order to do the
    processing
  • // Code the doGet method
  • public void doPost( HttpServletRequest request,
  • HttpServletResponse response)
  • throws IOException,

  • ServletException
  • doGet( request, response )

4
Form processing with Servlets
  • To process a form, the doGet (or doPost) argument
    request can call the following methods (just like
    the implicit object request calls them in a JSP)
  • getQueryString( )
  • getParameter( String )
  • getCookies( )
  • getSession( )
  • getAttribute( String )
  • getAttributeNames( )

5
Form processing with Servlets
  • Place form.html in webapps directory
  • ltform action "go" method "POST"gt
  • go should map to processForm in web.xml
  • processForm.class should be in a package inside
    the WEB-INF/classes directory

6
Form processing with Servlets
  • In web.xml
  • ltservletgt
  • ltservlet-namegtprocessFormlt/servlet-namegt
  • ltservlet-classgtmypackage.processFormlt/servlet-c
    lassgt
  • lt/servletgt
  • ltservlet-mappinggt
  • ltservlet-namegtprocessFormlt/servlet-namegt
  • lturl-patterngt/golt/url-patterngt
  • lt/servlet-mappinggt
Write a Comment
User Comments (0)
About PowerShow.com