Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

A step-by-step guide on how to create and invoke Java Servlets from HTML forms. It covers the creation of a simple Java program, saving and compiling the file, registering the servlet in web.xml, starting the Tomcat module, creating registration and login forms using HTML and JavaScript, writing Java programs to invoke servlets, and displaying registration details and user information. The document also includes the code for web.xml, hello.java, form1.html, form1.java, and form2.html files.

Typology: Assignments

2020/2021

Uploaded on 06/18/2021

raj-saranya
raj-saranya 🇮🇳

2 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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

</servlet-mapping> <servlet-name>form1</servlet-name> <servlet-class>form1</servlet-class> <servlet-mapping> <servlet-name>form1</servlet-name> <url-pattern>/f1</url-pattern> </servlet-mapping> <servlet-name>form2</servlet-name> <servlet-class>form2</servlet-class> <servlet-mapping> <servlet-name>form2</servlet-name> <url-pattern>/f2</url-pattern> </servlet-mapping> (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

    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"+ "<body bgcolor="AntiqueWhite"><h align="center">PHOTO STANDY PRICE LIST


    \n"+ "<table border="2"style="border-color: #000000;background-color: Crimson; color: white; " align="center">\n"+ "REQUIREMENTPRICE</ th>SIZETHICKNESS\n"+ "\n"+ "4 PHOTOS Rs 1000 inches 8 mm\n"+ "\n"+ "\n"+ ""+ ""); } if(user.equals("Name Frame")) { out.println(docType + "\n"+ ""+title+"\n"+ "<body bgcolor="AntiqueWhite"><h align="center">NAME FRAME PRICE LIST


    \n"+ "<table border="2"style="border-color: #000000;background-color: Crimson; color: white;" align="center">\n"+

    "REQUIREMENTPRICE</ th>SIZETHICKNESS\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.