03 handling requests

344 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
344
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

03 handling requests

  1. 1. 03-Handling Requests<br />DhrubojyotiKayal<br />
  2. 2. Form data as client request<br />Creating and submitting HTML forms<br />Reading request parameters<br />Agenda<br />
  3. 3. Need for forms<br />HTML forms <br />Fields – input text , radio, check box etc<br />Data in these fields come along on button click to submit the form<br />Result of form submission<br />http://domain/empweb/simpleservlet?name=dhrubo&profession=IT&age=31<br />Form data as client request<br />
  4. 4. <form action=“SimpleServlet“ method=“post”><br /><center><br />First name:<br /><input type=“text" name="firstName" value=""><BR><br />Last name:<br /><input type=“text" name="lastName" value=""><br /><P><br /><input type=“submit“><br /></center><br /></form><br />Create & Submit HTML forms<br />
  5. 5. request.getParameter("name")<br />Returns URL-decoded value of first occurrence of name in query string<br />Works identically for GET and POST requests<br />Returns null if no such parameter is in query data<br />request.getParameterValues("name")<br />Returns an array of the URL-decoded values of all<br />occurrences of name in query string<br />Returns a one-element array if param not repeated<br />Returns null if no such parameter is in query<br />request.getParameterNames() or<br />request.getParameterMap()<br />Returns Enumeration or Map of request params<br />Usually reserved for debugging<br />Reading form data<br />
  6. 6. Write a servlet which echoes all the request parameters and their values<br />Excerise<br />
  7. 7. Q&A<br />

×