Docsity

Java Servlets: Creating and Invoking Servlets from HTML Forms, Assignments of Internet and Information Access

Toggle sidebar
bg1
\**************************************************************************
EXNO:4A INVOKING SERVLETS FROM HTML FORMS
DATE:
**************************************************************************\
AIM:
To write programs in Java using Servlets to Invoke basic servlet response page , Invoke
servlets from HTML page with minimum form elements , Invoke servlets from HTML
forms, do some logical processing in the servlet and display the response.
PROCEDURE:
STEP1: Create a simple java program invoking a servlet to display some information
STEP2:Save the java file and compile it in the command line
STEP3:Save the servlet’s file name in the web.xml file
STEP4:Open Xampp and start the required module.
STEP5: Once the tomcat module starts, in the browser give localhost:8080/hello.
STEP6:The output will be displayed in the browser window as hello world.
STEP7:Create a simple registration form and login forms using html and stylesheet.
STEP8:Write programs in java to invoke servlets for displaying registration details and to
proceed further
STEP9:Now after filling the registration form successfully just open the localhost:8080/f1 ,to
view the registered details of the user in a webpage.
STEP10:Now after logining successfully using login html , you will be able to view the user
details and information.
PROGRAM:
web.xml
<!--hello program-->
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Java Servlets: Creating and Invoking Servlets from HTML Forms and more Assignments Internet and Information Access in PDF only on Docsity!

**************************************************************************

EXNO:4A INVOKING SERVLETS FROM HTML FORMS

DATE:

**************************************************************************\

AIM:

To write programs in Java using Servlets to Invoke basic servlet response page , Invoke servlets from HTML page with minimum form elements , Invoke servlets from HTML forms, do some logical processing in the servlet and display the response. PROCEDURE: STEP1: Create a simple java program invoking a servlet to display some information STEP2: Save the java file and compile it in the command line STEP3: Save the servlet’s file name in the web.xml file STEP4: Open Xampp and start the required module. STEP5: Once the tomcat module starts, in the browser give localhost:8080/hello. STEP6: The output will be displayed in the browser window as hello world. STEP7: Create a simple registration form and login forms using html and stylesheet. STEP8: Write programs in java to invoke servlets for displaying registration details and to proceed further STEP9: Now after filling the registration form successfully just open the localhost:8080/f1 ,to view the registered details of the user in a webpage. STEP10: Now after logining successfully using login html , you will be able to view the user details and information. **PROGRAM: web.xml **

hello hello

hello /hello


form1 form1

form1 /f1


form2 form2

form2 /f2

(i) hello.java import java.io.; import javax.servlet.; import javax.servlet.http.*; // Extend HttpServlet class public class hello extends HttpServlet {

if(username1.length < 8) { return_value=false; window.alert("user name less than 8 chars"); } if(username1==username2) { return_value=false; window.alert("both ids are same"); form1.txtusername2.value=""; } if(password1.length<6) { return_value=false; window.alert(" pwd should be > 6 char's "); form1.txtpassword1.value=""; form1.txtpassword2.value=""; } if(password1!=password2) { return_ value=false; window.alert("ur password mismatched "); form1.txtpassword1.value=""; form1.txtpassword2.value=""; } return return_value; }

REGISTRATION FORM

Name:



Age:



Gender:

male
female

Address:



Enter e-mail id :*



Password:*

(password should exceed 6 characters)

Confirm password:


Alternate mail:*




Known This Site Through

google
instagram
friends

Rate ur site

" Age: " + request.getParameter("age") + "\n" + " Gender: " + request.getParameter("gen") + "\n"

" Address: " + request.getParameter("address") + "\n" + " e-mail id : " + request.getParameter("txtusername1") + "\n" + " Password: " + request.getParameter("txtpassword1") + "\n" + " Confirm password: " + request.getParameter("txtpassword2") + "\n" + " Known This Site Through: " + request.getParameter("things") + "\n" + " Rate ur site: " + request.getParameter("rating") + "\n" + "\n" + "" + ""); } } (iii) form2.html


return_value=false; window.alert("user name less thn 8 chars"); } if(password1.length<6) { return_value=false; window.alert(" pwd should be > 6 char's "); form1.txtpassword1.value=""; form1.txtpassword2.value=""; } if(password1!=password2) { return_value=false; window.alert("ur password mismatched "); form1.txtpassword1.value=""; form1.txtpassword2.value=""; } return return_value; }

login here

Username



Password:



Confirm password:




"13 PHOTOS Rs 1290 inch8 mm\n"+ "\n"+ "\n"+ ""+ ""); } if(user.equals("Photo Standy")) { out.println(docType + "\n"+ ""+title+"\n"+ "PHOTO STANDY PRICE LIST


\n"+ "\n"+ "REQUIREMENTPRICESIZETHICKNESS\n"+ "\n"+ "4 PHOTOS Rs 1000 inches 8 mm\n"+ "\n"+ "\n"+ ""+ ""); } if(user.equals("Name Frame")) { out.println(docType + "\n"+ ""+title+"\n"+ "NAME FRAME PRICE LIST


\n"+ "\n"+

"REQUIREMENTPRICESIZETHICKNESS\n"+ "\n"+ "6 PHOTOS Rs 1200 inches 8 mm\n"+ "\n"+ "\n"+ ""+ ""); } } catch(Exception exp) { System.out.println(exp); } } } OUTPUT:

RESULT:

Thus the java programs invoking servlets were implemented, executed and the output has been verified.