0% found this document useful (0 votes)
5 views

Rush Il Java

Uploaded by

Shubham Mewada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Rush Il Java

Uploaded by

Shubham Mewada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

MODULE 3

Implement the following JSP & JSTL applications

a. Develop a simple JSP application to pass values from one page to


another with validations. (Name-txt, age-txt, hobbies-checkbox,
email-txt, gender-radio button).

b. Create a registration and login JSP application to register and


authenticate the user based on username and password using JDBC.

c. Create a JSP application to demonstrate the use of JSTL.

d. Create a Currency Converter application using EJB.

e. Develop a Simple Room Reservation System Application Using EJB.

f. Develop simple shopping cart application using EJB [Stateful Session


Bean].

g. Develop simple EJB application to demonstrate Servlet Hit


count using Singleton Session Beans.

Page No : 42
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

THEORY- PRACTICAL
Aim: Implement the following JSP & JSTL applications

Page No : 43
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

Page No : 44
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

Page No : 45
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

Page No : 46
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

Page No : 47
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

PRACTICAL 3

Aim: Implement the following JSP & JSTL applications

a. Develop a simple JSP application to pass values from one


page to another with validations. (Name-txt, age-txt,
hobbies-checkbox, email-txt, gender-radio button).

index.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="Validate.jspx" method="post">
Enter Your Name:<input type="text" name="name">
<br>
<br>
Enter Your Age:<input type="text" name="age">
<br>
<br>
Select Hobbies:<br>
Singing<input type="checkbox" name="hobbies" value="singing"><br>
Reading<input type="checkbox" name="hobbies" value="reading"><br>
Football<input type="checkbox" name="hobbies" value="football"><br>
<br>
<br>
Enter Email:<input type="email" name="email">
<br>
<br>
Select Gender:<br>
<input type="radio" name="gender" value="Male">Male<br>

Page No : 48
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

<input type="radio" name="gender" value="Female">Female<br>


<input type="radio" name="gender" value="Other">Other<br>
<br>
<br>
<input type="hidden" name="error">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

CheckerBean.java
package mypack;

public class CheckerBean


{
String name,age,hobbies,email,gender,error;
public void CheckerBean()
{
error="";

}
public void setName(String n)
{
name=n;
}
public void setAge(String n)
{
age=n;
}
public void setHobbies(String n)
{
hobbies=n;
}
public void setEmail(String n)
{
email=n;
}
public void setGender(String n)
{
gender=n;
}
public void setError(String n)

Page No : 49
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

{
error=n;
}

public String getName()


{
return name;
}
public String getAge()
{
return age;
}
public String getHobbies()
{
return hobbies;
}
public String getEmail()
{
return email;
}
public String getGender()
{
return gender;
}
public String getError()
{
return error;
}
public boolean validate()
{
boolean res=true;
if(name.trim().equals("") || (name==null))
{
error+="<br>Enter First Name";
res=false;
}
if(age.length() > 2 || (age==null))
{
error+="<br>Age Invalid";
res=false;
}
return res;

Page No : 50
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

}
}

Successful.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration Successful !!!</title>
</head>
<body>
<h1>Data Validated Successfully..!</h1>
</body>
</html>

Validate.jspx
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:directive.page contentType="text/html" pageEncoding="UTF-8" import =
"mypack.CheckerBean" />

<!-- any content can be specified here, e.g.: -->


<jsp:element name="text">
<jsp:attribute name="lang">EN</jsp:attribute>
<jsp:body>Validation Page</jsp:body>

<jsp:useBean id="obj" scope="request" class="mypack.CheckerBean">


<jsp:setProperty name="obj" property="*"/>
<jsp:scriptlet>if (obj.validate())
{
</jsp:scriptlet>
<jsp:forward page="Successful.jsp"/>
<jsp:scriptlet>
}else {
</jsp:scriptlet>
<jsp:include page="index.html"/>
<jsp:scriptlet>
}
</jsp:scriptlet>
<jsp:expression>obj.getError()</jsp:expression>
</jsp:useBean>

Page No : 51
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

</jsp:element>

</jsp:root>

OUTPUT:

Page No : 52
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

b. Create a registration and login JSP application to register and


authenticate the user based on username and password using JDBC.

login.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
<style>
body {
background-color:
#333; color: #ddd;
font-family: Arial, sans-serif;
padding: 20px;
}
form {
max-width: 400px;
margin: 0 auto;
background-color:
#333; padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
}
form label{
color: white;
}
input[type="text"], input[type="password"] {
width: calc(100% - 20px);

Page No : 53
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

padding:
10px; margin:
8px 0;
border: 1px solid #444;
background-color:
#444; color: #fff;
border-radius: 4px;
box-sizing: border-box;
}
input[type="submit"], input[type="reset"] {
width: 100%;
padding: 10px;
margin-top: 10px;
border: none;
background-color:
#4CAF50; color: white;
cursor: pointer;
border-radius:
4px; font-size:
16px;
}
input[type="submit"]:hover, input[type="reset"]:hover {
background-color: #45a049;
}
input[type="submit"]:active, input[type="reset"]:active
{ background-color: #3e8e41;
}
h2 {
color: white;
text-align:
center;
}
</style>
</head>
<body>
<form action="login.jsp" method="post">
<h2>User Login</h2>
<label for="username">Enter Username:</label>
<input type="text" id="username" name="username" required>

<label for="password">Enter Password:</label>


<input type="password" id="password" name="password" required>
<input type="submit" value="Login">
<input type="reset" value="Reset">
Page No : 54
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

</form>
</body>
</html>

index.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>
body {
background-color: #333;
color: #fff;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}

div {
width: 80%;
margin: 100px auto;
text-align: center;
}

h1 {
font-size: 1.5em;
margin-bottom: 20px;
}

a{
color: #fff;
text-decoration: none;
padding: 10px 20px;

Page No : 55
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

background-color: #555;
border-radius: 5px;
display: inline-block;
margin: 10px;
transition: background-color 0.3s ease;
}

a:hover {
background-color: #777;
}
</style>
</head>
<body>
<div>
<h1>New user?</h1><a href="register.html">Click Here TO Register</a>
<h1>Old user?</h1><a href="login.html">Click Here TO Login</a>
</div>
</body>
</html>

register.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>
body {
background-color:
#222; color: #ddd;
font-family: Arial, sans-serif;
padding: 20px;
}
form {
max-width: 400px;

Page No : 56
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

margin: 0 auto;
background-color:
#333; padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
}
input[type="text"], input[type="password"], input[type="email"] {
width: calc(100% - 20px);
padding:
10px; margin:
8px 0;
border: 1px solid #444;
background-color:
#444; color: #ddd;
border-radius: 4px;
box-sizing: border-box;
}
input[type="submit"], input[type="reset"] {
width: 100%;
padding: 10px;
margin-top: 10px;
border: none;
background-color:
#4CAF50; color: white;
cursor: pointer;
border-radius:
4px; font-size:
16px;
}
input[type="submit"]:hover, input[type="reset"]:hover {
background-color: #45a049;
}
input[type="submit"]:active, input[type="reset"]:active
{ background-color: #3e8e41;
}
h2 {
text-align: center;
}
</style>
</head>
<body>
<form action="register.jsp" method="post">
<h2>User Registration</h2>
<label for="username">Enter Username:</label>
Page No : 57
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

<input type="text" id="username" name="username" required>

<label for="password">Enter Password:</label>


<input type="password" id="password" name="password" required>

<label for="password_confirm">Re-Enter Password:</label>


<input type="password" id="password_confirm" name="password_confirm" required>

<label for="email">Enter Email:</label>


<input type="email" id="email" name="email" required>

<label for="country">Enter Country Name:</label>


<input type="text" id="country" name="country" required>

<input type="submit" value="Register">


<input type="reset" value="Reset">
</form>
</body>
</html>

<%--
Document : register
Created on : Jul 12, 2024, 12:40:28
PM Author : Admin
--%>

register.jsp
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String s1 = request.getParameter("username");
String s2 = request.getParameter("password");
String s3 = request.getParameter("password_confirm");
String s4 = request.getParameter("email");
String s5 = request.getParameter("country");

Page No : 58
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

if(s2.equals(s3))
{
try{

Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
PreparedStatement pst =conn.prepareStatement("insert into registration_041
values(?,?,?,?)");
pst.setString(1, s1);
pst.setString(2, s2);
pst.setString(3, s4);
pst.setString(4, s5);
int rows = pst.executeUpdate();
if(rows==1)
{
out.println("Mubarakho !!! Registration Succesfully !!!");
}
else
{
out.println("Kuch Toh Gadbad Hai...!!! Firse try Kar!!!");

%>
<jsp:include page="register.html"></jsp:include>
<%
}
}

catch(Exception e)
{

out.write("Exception :"+e);
}
}
else
{
out.print("Password Mismatch..!!! Reenter All Details");

%>

<jsp:include page="register.html"></jsp:include>
<%

Page No : 59
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

}
%>
</body>
</html>

login.jsp
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String s1 =request.getParameter("username");
String s2 =request.getParameter("password");

try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn
=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
PreparedStatement pst =conn.prepareStatement("select * from registration_041
where username=?");
pst.setString(1,s1);
ResultSet rs = pst.executeQuery();

if (rs.next())
{
if(rs.getString(2).equals(s2))
{
out.print("Login HoGaya Mubarakho !!");
}

else
{
out.print("Appka Password Galat hai !!");
%>
<jsp:include page="login.html"></jsp:include>
<%

Page No : 60
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

}
}
else
{
out.print("Tum Exist Nhi karte Register Karo Jaakar");
%>
<jsp:include page="register.html"></jsp:include>
<%

}
catch(Exception e)
{
out.print("Exception:"+e); %>
</body>
</html>

Page No : 61
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

OUTPUT:

Page No : 62
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

c. Create a JSP application to demonstrate the use of JSTL.

index.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Jsp Module</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<h1>Choose Option</h1>
<a href="insert.jsp">Insert Record</a><br><br>
<a href="display.jsp">Display Record</a>
</body>
</html>

update.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"
import="java.io.*,java.util.*,java.sql.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>

Page No : 63
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

<body>
<sql:setDataSource var="dbsource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test" user="root" password="root"/>
<sql:query dataSource="${dbsource}" var="result">
SELECT * from product_details120 WHERE pid=?;
<sql:param value="${param.pid}"/>
</sql:query>
<h3>Update</h3>
<form action="updatedb.jsp">
<table>
<tr>
<th>Product Name</th>
<th>Quantity</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>

<td><input type="hidden" value="${param.pid}" name="pid" >


<input type="text" value="${param.pname}" name="pname">
</td>
<td><input type="text" value="${param.quantity}"
name="quantity"></td>
<td><input type="submit" value="Update"></td>
</tr>
</c:forEach>
</table>
<a href="index.html">Go Home</a>
</form>
</body>
</html>

updated.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"
import="java.io.*,java.util.*,java.sql.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>

Page No : 64
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

<body>
<sql:setDataSource var="dbsource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test" user="root" password="root"/>
<sql:update dataSource="${dbsource}" var="count">
UPDATE product_details120 SET pname=?, quantity=? WHERE
pid='${param.pid}';
<sql:param value="${param.pname}"/>
<sql:param value="${param.quantity}"/>
</sql:update>
<c:if test="${count>=1}">
<font size="5" color="green"> wohohohohohohoho data updated </font><br>
<a href="index.html">Go Home</a>
</c:if>
</body>
</html>

insert.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Insert Page</title>
</head>
<body>
<form action="insertdb.jsp">
<table border="1">
<tr>
<th colspan="2"> Purchase Product</th>
</tr>
<tr>
<td>Product Id</td>
<td><input type="number" name="pid"></td>
</tr>
<tr>
<td>Product Name</td>
<td><input type="text" name="pname"></td>
</tr>
<tr>
<td>Quantity</td>
<td><input type="number" name="quantity"></td>

Page No : 65
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

</tr>
<tr>
<td><input type="submit" name="save" value="Save"></td>
<td><input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</form>
<font color="red">
<c:if test="${not empty param.errMsg}">
<c:out value="${param.errMsg}"/>
<a href="index.html">Go Back</a>
</c:if>
</font>
<font color="green">
<c:if test="${not empty param.susMsg}">
<c:out value="${param.susMsg}"/>
<a href="index.html">Go Back</a>
</c:if>
</font>
</body>
</html>

inserted.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"
import="java.io.*,java.util.*,java.sql.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<c:if test="${empty param.pid or empty param.pname or empty param.quantity}">
<c:redirect url="insert.jsp">
<c:param name="errMsg" value="Please enter product details"/>
</c:redirect>
</c:if>
<sql:setDataSource var="dbsource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test" user="root" password="root"/>
<sql:update dataSource="${dbsource}" var="result">

Page No : 66
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

Insert into product_details120 VALUES(?,?,?)


<sql:param value="${param.pid}"/>
<sql:param value="${param.pname}"/>
<sql:param value="${param.quantity}"/>
</sql:update>
<c:if test="${result>=1}">
<font size="5" color="green">Data inserted</font>
<c:redirect url="insert.jsp">
<c:param name="susMsg" value="Data inserted"/>
</c:redirect>
</c:if>
</body>
</html>

display.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.io.*,java.util.*,java.sql.*"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP display Page</title>
<script>
function confirmGo(m,u){
if(confirm(m)){
window.location = u;
}
}
</script>
</head>
<body>
<sql:setDataSource var="dbsource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test" user="root" password="root"/>
<sql:query dataSource="${dbsource}" var="result">
SELECT * from product_details120;
</sql:query>
<form action="">
<center>
<table border="1">
<tr>

Page No : 67
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

<th>Product ID</th>
<th>Product Name</th>
<th>Product Quantity</th>
<th colspan="2">Action</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.pid}"/></td>
<td><c:out value="${row.pname}"/></td>
<td><c:out value="${row.quantity}"/></td>
<td><a href="update.jsp?pid=<c:out
value="${row.pid}"/>">update</a></td>
<td><a href="javascript:confirmGo('Sure to delete this
record?','deletedb.jsp?pid=<c:out value="${row.pid}"/>')">Delete</a></td>
</tr>
</c:forEach>
</table>
</form>
<a href="index.html">Go Home</a>
</center>
</body>
</html>

delete.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"
import="java.io.*,java.util.*,java.sql.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Delete JSP Page</title>
</head>
<body>
<sql:setDataSource var="dbsource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test" user="root" password="root"/>

<sql:update dataSource="${dbsource}" var="count">


DELETE FROM product_details120 WHERE pid='${param.pid}';

Page No : 68
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

</sql:update>

<c:if test="${count>=1}">
<font size="5" color="green"> Data deleted successfully! </font><br>
<a href="index.html">Go Home</a>
</c:if>
</body>
</html>

OUTPUT:

Page No : 69
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

d. Create a Currency Converter application using EJB.


CCBean.java
package mybean;
import javax.ejb.Stateless;
@Stateless
public class CCBean {
public
CCBean(){}
public double r2Dollar(double r){
return r/83.90;
}
public double d2Rupees(double d){
return d*83.90;
}
}

CCServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import mybean.CCBean;

@WebServlet(urlPatterns = {"/ccservlet"})

public class ccservlet extends HttpServlet {

@EJB
CCBean obj;

protected void processRequest(HttpServletRequest request, HttpServletResponse


response)
throws ServletException, IOException {

Page No : 70
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {

out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet ccservlet</title>");
out.println("</head>");
out.println("<body>");

double amt = Double.parseDouble(request.getParameter("amount"));


if (request.getParameter("r1").equals("r2d"))
{
double result = obj.r2Dollar(amt);
out.println("Dollar = "+result);
}
else{
double result = obj.d2Rupees(amt);
out.println("Rupees = "+result);
}
out.println("</body>");
out.println("</html>");
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign


on the left to edit the code.">

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

@Override
public String getServletInfo() {
return "Short description";

Page No : 71
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

}// </editor-fold>
}

index.html
<!DOCTYPE html>
<html>
<head>
<title>Module 3d</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="ccservlet">
Enter amount <input type="text" name="amount"><br>
Select Conversion Type:<input type="radio" name="r1" value="r2d">Rupees to
Dollar <input type="radio" name="r1"
value="d2r">Dollar to Rupees
<br>
<input type="reset" value="RESET">
<input type="Submit" value="CONVERT">
</form>
</body>
</html>

Page No : 72
Advanced Java –Rushil Bhimani - 53003220091 - Batch 4

OUTPUT:

Page No : 73

You might also like