HTML Form page to servlet Communication: adv java Advance Java Servlet Programming Tutorial
Form Page can generate request to servlet program; form data as request parameter as values.
Here form component name like text box, button, radio button etc acts as request param names and values act as request param values.
Form page generate request to that servlet program whose request url is specified in action attribute of form tag.
Form page can generate two methodologies based requests.
1) GET method (Useful to send limited amount of data i.e. max of 256kb)
2) POST method (Useful to send unlimited amout of data)
To process "GET" method based request of form page, we need to override doGet(-,-) method in our servlet program. Similarly to process "POST" method request of form page we need to override doPost(-,-) method in our servlet program.
Avoid placing request processing logic in service(-,-) method and prefer placing logic in doXxx(-,-) methods.
Prototype of doXxx(-,-) methods:
--------------------------------
public void doXxx(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
Total 7 doXxx() methods are there:
---------------------------------
doGet(-,-) //Very much required in our regular servlet program
doPost(-,-) //Very much required in our regular servlet program
doDelete(--)
doPut(--)
doHead(--)
doOption(--)
doTrace(--)
#Example web application on HTML Form Page to servlet communication:
===================================================================
DDS:
10VoterApp (web-root folder)
----------
|
|--------input.html,tip.gif
|--------WEB-INF (also called as private diectory or webapp)
|
|------web.xml (cofiguration file)
|------classes
|
|------VoterServlet.java
|------p1 (package)
|
|---VoterServlet.class
Note:
When the servlet program is placed in a package it must be configured in web.xml file along with package name as fully qulified name (p1.VoterServlet)
When multiple modules are there in web application then its recommended to place in separate package.
input.html
----------
Request URL:
http://localhost:2020/10VoterApp/input.html
javac -d . VoterServlet.java
#HTML #Form #page #to #servlet #Communication: #adv java #Advance #Java #Servlet #Programming #Tutorial