Calling
of a servlet on the get method of html file.
To do this exercise :-
1. Create a Dynamic web project in Eclipse.
2. Give the name of the project.
3. Select the generate web.xml deployment descriptor check box.
4. Now select the project from the project explorer and right click a new a HTML File.
5. Now select the project from the project explorer --> select Web content Folder and right click --> new --> HTML File a give the name of the index file as index.html --> click on finish.
6. Now do the coding of html file as follows
7. When you will run it on server it will looks like as given below:- create a form , textbox, password box and a button.
8. This was the procedure for creating and html file. Now we want to pass the value of user name and password to our servlet which is already mentioned in <form> tag under the action attribute. So now create a servlet.
9. To create servlet select the java resource folder and right click --> new --> servlet.
10. Now give the name of package and class in the next dialog box as :-
Project name : com.servlet.org
Class name : servlet2 (this would be same as given in html file)
11. Click on next --> next -->now you have to select the methods which are inherited from the base class like doGet() and doPost(). Select doGet() because we had given the method=”get” in the form tag of html file.
This will generate a code now modify the doGet() method as
12. When we run our html file on server then we have to enter username and password which it will send to the servlet using get method and it will execute whatever is written in it.
No comments:
Post a Comment