Showing posts with label WTAD. Show all posts
Showing posts with label WTAD. Show all posts

postheadericon GTU WTAD Old Question Paper


postheadericon GTU WTAD Important Questions Bank


Unit-1 HTML and JavaScript 

  • Give DOM hierarchy? Explain properties, methods and events for text element of Html form
  • What is JavaScript? Explain the advantages of JavaScript.
  • What is CSS? Explain the types of CSS.
  • Explain function in JavaScript?
  • Explain Date and Time functions in JavaScript
  • Explain Object creation and modification in Javascript
  • Explain Following HTML Tag with example: (1)
    • (i) Title, Head 
    • (ii) OL, UL , DL
    • (iii) Table with TH,TR,TD
  • Write a java script to check whether a number entered in textbox is prime or not.
  • In Javascript, eval("2 + 0.56") returns ______. (1)
  • In HTML, <ol> tag is used to create list items with bullets. (True / False) (1)
  • Write the advantages of JavaScript. Explain any three methods of Date and String objects of JavaScript. (7)
  • Explain the various types of inputs provided by HTML. (7)
  • Write a Javascript that changes background color to red if user presses the mouse button. (4)
  • Write a JavaScript function to add two numbers when user presses submit button. (3)
  • JavaScript is created by______ . (Sun, Microsoft, Netscape) (1)
  • What will be assign in variable mca by following JavaScript var mca = parseInt(“0xff”); Ans:255  (1 mark)
  • JavaScript is compiled and executed at client. (True / False) (1)
  • _________ is only property of string object in JavaScript. (1)
  • Java is _______________and JavaScript is ___________________. (2)
  • True or False. JavaScript Ignores White Space. (1)
  • What is the code in HTML so that someone can mail by just clicking on text? (1)
  • Write a code for create a multiple list in HTML. (1)
  • Which two methods are used for takes keyboard input and screen output in Java Script? (1)
  • What is the correct JavaScript syntax to write “Hello World”? (1)
  • HTML elements with no content are called _______ elements (1)
  • Explain Array in JavaScript with Example (3)
  • Write a JavaScript to input two numbers and find out max. Put validation - both value is not null. (7)
  • The <select> tag allows multiple choice selection from list of choices that are offered. (True/False) (1)
  • The Date object contains information about a particular date and time. (True/False) (1)
  • Explain DOM hierarchy. List two important methods of Window and Document Object. (7)
  • What is special about Math object? Explain any two methods of String, Date and Array object.(7)
  • Which tag is used to write JavaScript in HTML? (1)
  • Explain functionality of Join() & Reverse() function of array in JavaScript. (2)
  • Explain basic structure of HTML document. (3)
  • Explain various dialog box provided by JavaScript. (3)
  • Explain Table tag of HTML with example. (7)
  • We can save external JavaScript file with ____ extension. (1)


postheadericon RequestDispatcher include Example




postheadericon JavaScript Exercises



1.  Write a JavaScript that shows how a variable’s type can be changed on-the-fly.
2.  Write a JavaScript that demonstrates the use of +=,-=,*=,/= operators.
3.  Create a Form in HTML with two fields, minimum and maximum, write JavaScript to validate that only numeric value is entered in both, and the value entered in minimum is less than the value entered in maximum.
4.  Write a JavaScript that finds out multiples of 10 in 0 to 10000. On the click of button start the timer and stop the counter after 10 seconds. Display on the screen how many multiples of 10 are found out within stipulated time.
5.  Write a JavaScript to generate two random numbers and find out maximum and minimum out of it.

postheadericon HTML Exercises





1.      Write HTML code to develop a web page having the background in red and title “My First Page” in any other color.
2.     Create a HTML document giving details of your name, age, telephone, address, Pin code & enrollment no. aligned in proper order (About Me page for you)
3.       Write HTML code to design a page containing a text in a paragraph give suitable heading style. Create three paragraphs each should differently align like left, right and center.
4.       Create a page to show different attribute of Font tag.
5.       Create a page to show different attribute italic, bold, underline, strike, subscript superscript etc.

postheadericon JSP JDBC Example

Develop a JSP Page to perform database driven operations like insert, Delete, Update and selection with table named Student having fields like StudId, Name, Address, result.



Create Table in Oracle / MySQL [ student ]

CREATE TABLE   student (
StudId NUMBER( 4 ) NOT NULL ,
Name VARCHAR( 15 ) NOT NULL ,
Address VARCHAR( 20 ) NOT NULL ,
result NUMBER( 8 ) NOT NULL
)


postheadericon example of preparedstatement in java


Create Table in MySql [ Employee ]


CREATE TABLE  `wtad`.`Employee` (
`EmpId` INT( 4 ) NOT NULL ,
`Empname` VARCHAR( 15 ) NOT NULL ,
`Emp_desig` VARCHAR( 20 ) NOT NULL ,
`Emp_J_Date` VARCHAR( 20 ) NOT NULL ,
`Emp_Salary` INT( 8 ) NOT NULL
) ENGINE = MYISAM ;

Create Table in Oracle [ Employee ]

postheadericon example of page directive in jsp

index.jsp

<html>
<head>
<title>EX-35</title>
</head>
<body>
<%@ page language="java" %>
<%@ page info="A code from www.BipinRupadiya.com"  %>
<ul>
<li><a href="import.jsp">Example of page directive import </a></li>
<li><a href="isThreadsafe.jsp">Example of page directive isThreadsafe </a></li>
<li><a href="jsp-forward.jsp">Example of page directive jsp-forward </a></li>
<li><a href="contentType.jsp">Example of page directive contentType </a></li>
<li><a href="errorPage.jsp">Example of page directive isErrorPage and errorPage </a></li>
</ul>
<body>
</html>


postheadericon Example of requestdispatcher

index.jsp

<html>
<head>
<title>MySqlLogin</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:300px;
left:5in;
border-style:solid;
}
</style>
</head>

postheadericon JSTL standard tag library Example

index.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<HTML>
<HEAD>
<TITLE>WTAD: Ex31 : www.BipinRupadiya.com</TITLE>
</HEAD>
<BODY>
<h3>Example of JSTL standard tag library.</h3>
<ul>
<li><a href="set.jsp">set, remove and out</a></li>
<!-- Example of c:for -->
<li><a href="for.jsp">for</a></li>
<!-- Example of c:if -->
<li><a href="if.jsp">if</a></li>
<!-- Example of c:choose -->
<li><a href="choose.jsp">choose</a></li>
<!-- Example of c:redirect and c:param -->
<li><a href="redirect.jsp">redirect</a></li>

</ul>
</BODY>
</HTML>

postheadericon Difference between GenericServlet and HttpServlet

GenericServlet:


  • As name says it Generic in nature. Means GenericServlet is protocol-independent.
  • import  javax.servlet.servlet package
  • super class of GenericServlet are java.lang.Object and it implements three interfaces Servlet, ServletConfig and java.io.Serializable
  • To write a generic servlet, override the abstract service().
  • GenericServlet  lifecycle methods use ServletConfig interface.
  • GenericServlet implements the log() from ServletContext interface.
  • Prototype:
    • public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable
  • Example:

postheadericon 16. Assume that the information regarding the marks for all the subjects of a student in the last exam are available in a database, Develop a Servlet which takes the enrollment number of a student as a request parameter and displays the marksheet for the student.



1. Create Database in MySql / Oracle / Access


You can choose any database. Here, I provide the solution to connect database like MySQL, Oracle,    and Microsoft Access




2. Create Table IN MySQL
create table MARK (EnNo VARCHAR(10),Code VARCHAR(10),Name VARCHAR(10),Mark INT(3));


3. Create Table IN Oracle
create table MARK (EnNo VARCHAR(10),Code VARCHAR(10),Name VARCHAR(10),Mark NUMBER (3));


    


4. Create Web Application in tomcat using following code              


index.jsp





<HTML>  
<HEAD>  
<TITLE>Ex-16 : www.BipinRupadiya.blogspot.in</TITLE>  
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:400px;
left:5in;
border-style:solid;
}
</style>

</HEAD>  
<BODY>
<div class="abc"  id="f1">
<br>
<center>
<h3>
<FORM METHOD=POST ACTION="Ex16.com">
Enrollment No.: <input type=TEXT name = "txtEnNo" >
<BR><BR><input type="submit" value="Show Result">
</FORM>
</div>
</BODY>
</HTML>


Ex16.java





import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.servlet.annotation.WebServlet;

@WebServlet("/Ex16.com")
public class Ex16 extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
String enNo = request.getParameter("txtEnNo");
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        try
{
//Connect To MySql
/* Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/wtad","root","admin");

*/
//Connect To Oracle

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","scott","tiger");


//Connect To Access
/*
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:test","bipin","rupadiya");
*/


String sql = "select * from MARK where EnNo = ?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, enNo);

ResultSet rs= ps.executeQuery();

out.println("<HTML><BODY bgcolor='#ababff'>");
            out.println("<center><h1> Marksheet</h1>");
            out.println("<TABLE BORDER=1 cellpadding='5px' width=50%");

out.println("<TR><TH colspan=3> Enrollment No.:"+enNo+"</TH></TR>");
out.println("<TR><TH>CODE </TH> <TH>NAME </TH> <TH> GRADE </TH></TR>");

            if(rs == null)
            {  
                out.println("<h1> Result Not Found... </h1>");
            }
            else
            {
while(rs.next())
                {
                    out.println("<TR>");
                        out.println("<TD>"+rs.getString(2)+"</TD>");
out.println("<TD>"+rs.getString(3)+"</TD>");
out.println("<TD>"+rs.getInt(4)+"</TD>");                          
                    out.println("</TR>");
                }
out.println("<TR><TH colspan=3> <a href='index.jsp'>Home</a> </TH></TR>");
out.println("</TABLE></CENTER></BODY></HTML>");
                rs.close();
                ps.close();
                con.close();
            }
        }
        catch(SQLException e)
        {
                out.println(e);
        }
catch(ClassNotFoundException e)
{
out.println(e);
}
        catch(Exception e)
        {
            out.println(e);
        }    

    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        doGet(request, response);
    }
}






postheadericon 26.Develop an application to write a "page-composite" JSP that includes other pages or passes control to another page. (Hint: Use <jsp:include> or <jsp:forward>).


index.jsp


<html>
<head>
<title>EX-26</title>
<style>
div
{
background:#ababff;
position:absolute;
width:1000px;
left:110px;

}

.abcH
{
top:0.5cm;
width:1000px;
border-style:solid;
}

.abcL
{
top:200px;

width:1000px;
}

.abcF
{
top:500px;
width:1000px;
border-style:solid;
}
</style>
</head>

<body bgcolor="#ababff">
<%@ include file="/header.jsp" %>
<jsp:include page="/login.jsp" />
<jsp:include page="/footer.jsp" />
<br>
</div>
</body>
</html>


header.jsp


<div class="abcH"  id="f1">
<br>
<table align="center">
<tr>
<td><h1>www.BipinRupadiya.blogspot.in<h1></td>
</tr>
</table>

</div>



login.jsp



<div class="abcL"  id="f1">
<br>
<form method="POST" action="result.jsp">
<table align="center">
<tr>
<td colspan=2 align=center> <h3>Login</h3><hr></td>
</tr>
<tr>
<td>User Name : </td>
<td><input type="text" name="txtUsr"></td>
</tr>
<tr>
<td>Password :</td>
<td><input type="password" name="txtPwd"></td>
</tr>
<tr>
<td colspan=2 align=center><hr>
<input type="submit" value="Login">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
</div>


footer.jsp


<div class="abcF"  id="f2">
<br>
<table align="center">
<tr>
<td><h3>&copy; Mr. Bipin S Rupadiya<h3></td>
</tr>
</table>
</div>


result.jsp


<%
String d;
if(request.getParameter("txtUsr").equals("bipin") &&
request.getParameter("txtPwd").equals("rupadiya"))
d="welcome.jsp";
else
d="index.jsp";
%>
<jsp:forward page="<%= d%>" />


welcome.jsp


<html>
<head>
<title>EX-26</title>
<style>
div
{
background:#ababff;
position:absolute;
width:1000px;
left:110px;

}

.abcH
{
top:0.5cm;
width:1000px;
border-style:solid;
}

.abcL
{
top:200px;

width:1000px;
}

.abcF
{
top:500px;
width:1000px;
border-style:solid;
}
</style>
</head>

<body bgcolor="#ababff">
<%@ include file="/header.jsp" %>
<div class="abcL">
<center><h1>Welcome</h1><br>
<br>
<a href="index.jsp">Home</a>
</div>
<jsp:include page="/footer.jsp" />
<br>
</div>
</body>
</html>



postheadericon 27. You want to reduce the amount of Java coding in your JSP using a JavaBean component. (Hint: Use with the name of your bean).



Simple Interest Calculation Using Java Beans (Form Beans)

index.jsp


<html>
<head>
<title>EX-23</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:400px;
left:5in;
border-style:solid;
}
</style>

</head>
<body>

<div class="abc"  id="f1">
<br>
<form method="POST" action="result.jsp">
<table align="center">
<tr>
<td colspan=2 align=center><h3>Simple Interest</h3><hr>
</td>
</tr>
<tr>
<td>Amount : </td>
<td><input type="text" name="p"></td>
</tr>
<tr>
<td>Rate :</td>
<td><input type="text" name="r"></td>
</tr>
<tr>
<td>Time :</td>
<td><input type="text" name="n"></td>
</tr>

<tr>
<td colspan=2 align=center>
<hr>
<input type="submit" value="Calculate">
<input type="reset" value="Clear">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>



result.jsp


<html>
<head>
<title>EX-23</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:400px;
left:5in;
border-style:solid;
}
</style>

</head>
<BODY>
<CENTER>


<jsp:useBean id="si" class="bsr.SimpleIntrest" />

<jsp:setProperty name="si" property="*" />

<div class="abc"  id="f1">
<br>
<table width="50%" align="center">
<tr>
<th colspan=2><h3> Simple Interest</h3><hr></th>
</tr>
<tr>
<td>Amount : </td>
<td><jsp:getProperty name="si" property="p" /></td>
</tr>
<tr>
<td>Rate :</td>
<td><jsp:getProperty name="si" property="r" /></td>
</tr>
<tr>
<td>Time :</td>
<td><jsp:getProperty name="si" property="n" /></td>
</tr>
<tr>
<td>Interest :</td>
<td><jsp:getProperty name="si" property="intrest" /></td>
</tr>
<tr>
<th colspan=2> <hr><a href="index.jsp">Home</a></th>
</tr>
</table>
</form>
</div>
</body>
</html>



SimpleIntrest.java 


package bsr;
public class SimpleIntrest
{
private float p=1;
private float r=1;
private float n=1;

// Principal Amount
public float getP()
{
return(p);
}
public void setP(float v)
{
this.p = v;
}

// Rate of Interest
public float getR()
{
return(r);
}
public void setR(float v)
{
this.r = v;
}

// Number of Years
public float getN()
{
return(n);
}
public void setN(float v)
{
this.n = v;
}

//Calculate Interest
public float getIntrest()
{
return((p*r*n)/100);
}
}




postheadericon 23. Develop a interest calculation application in which user will provide all information in HTML form and that will be processed by servlet and response will be generated back to the user.



1. Using  Servlet

index.jsp


<html>
<head>
<title>EX-23</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:400px;
left:5in;
border-style:solid;
}
</style>

</head>
<body>

<div class="abc"  id="f1">
<br>
<form method="get" action="/Ex23/bipinrupadiya.blogspot.com">
<table align="center">
<tr>
<td colspan=2 align=center><h3>Simple Interest</h3><hr>
</td>
</tr>
<tr>
<td>Amount : </td>
<td><input type="text" name="p"></td>
</tr>
<tr>
<td>Rate :</td>
<td><input type="text" name="r"></td>
</tr>
<tr>
<td>Time :</td>
<td><input type="text" name="n"></td>
</tr>

<tr>
<td colspan=2 align=center>
<hr>
<input type="submit" value="Calculate">
<input type="reset" value="Clear">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>


Ex23.java


package bsr;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;

/** Ex23 simple Interest. by Bipin S rupadiya */

@WebServlet("/bipinrupadiya.blogspot.com")
public class Ex23 extends HttpServlet
{
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
    {
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();
     
        float p=Float.parseFloat(request.getParameter("p"));
        float r=Float.parseFloat(request.getParameter("r"));
        float n=Float.parseFloat(request.getParameter("n"));
        float i=(p*r*n)/100;
        out.println("<br><h1>Simple Interest will be : "+i);
    }
}



2. Using Java Beans (Form Beans)

index.jsp


<html>
<head>
<title>EX-23</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:400px;
left:5in;
border-style:solid;
}
</style>

</head>
<body>

<div class="abc"  id="f1">
<br>
<form method="POST" action="result.jsp">
<table align="center">
<tr>
<td colspan=2 align=center><h3>Simple Interest</h3><hr>
</td>
</tr>
<tr>
<td>Amount : </td>
<td><input type="text" name="p"></td>
</tr>
<tr>
<td>Rate :</td>
<td><input type="text" name="r"></td>
</tr>
<tr>
<td>Time :</td>
<td><input type="text" name="n"></td>
</tr>

<tr>
<td colspan=2 align=center>
<hr>
<input type="submit" value="Calculate">
<input type="reset" value="Clear">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>



result.jsp


<html>
<head>
<title>EX-23</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:400px;
left:5in;
border-style:solid;
}
</style>

</head>
<BODY>
<CENTER>


<jsp:useBean id="si" class="bsr.SimpleIntrest" />

<jsp:setProperty name="si" property="*" />

<div class="abc"  id="f1">
<br>
<table width="50%" align="center">
<tr>
<th colspan=2><h3> Simple Interest</h3><hr></th>
</tr>
<tr>
<td>Amount : </td>
<td><jsp:getProperty name="si" property="p" /></td>
</tr>
<tr>
<td>Rate :</td>
<td><jsp:getProperty name="si" property="r" /></td>
</tr>
<tr>
<td>Time :</td>
<td><jsp:getProperty name="si" property="n" /></td>
</tr>
<tr>
<td>Interest :</td>
<td><jsp:getProperty name="si" property="intrest" /></td>
</tr>
<tr>
<th colspan=2> <hr><a href="index.jsp">Home</a></th>
</tr>
</table>
</form>
</div>
</body>
</html>



SimpleIntrest.java [ JavaBean ]


package bsr;
public class SimpleIntrest
{
private float p=1;
private float r=1;
private float n=1;

// Principal Amount
public float getP()
{
return(p);
}
public void setP(float v)
{
this.p = v;
}

// Rate of Interest
public float getR()
{
return(r);
}
public void setR(float v)
{
this.r = v;
}

// Number of Years
public float getN()
{
return(n);
}
public void setN(float v)
{
this.n = v;
}

//Calculate Interest
public float getIntrest()
{
return((p*r*n)/100);
}
}



postheadericon 20. Write a JSP page, which uses the include directive to show its header and footer.



index.jsp


<html>
<head>
<title>EX-20</title>
<style>
div
{
background:#ababff;
position:absolute;
width:1000px;
left:110px;
border-style:solid;
}

.abcH
{
top:0.5cm;
width:1000px;
}

.abcF
{
top:500px;
width:1000px;
}
</style>
</head>

<body>
<%@ include file="/header.jsp" %>
<jsp:include page="/footer.jsp" />
<br>
</div>
</body>
</html>

header.jsp


<div class="abcH"  id="f1">
<br>
<table align="center">
<tr>
<td><h1>www.BipinRupadiya.blogspot.in<h1></td>
</tr>
</table>

</div>



footer.jsp


<div class="abcF"  id="f2">
<br>
<table align="center">
<tr>
<td><h3>&copy; Mr. Bipin S Rupadiya<h3></td>
</tr>
</table>
</div>



postheadericon 19. Write a simple JSP page to display a simple message (It may be a simple html page).



<html>
<head>
<title>EX-19</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:300px;
left:5in;
border-style:solid;
}
</style>
</head>

<body>

<div class="abc"  id="f1">
<center>
<br><br>
<b>Visit</b>
<br><br>
<%
out.println("<a href='www.bipinrupadiya.blogspot.in'>www.bipinrupadiya.blogspot.in</a>");
%>
<br><br><br>
</div>
</body>
</html>

postheadericon 18. Develop a Servlet to authenticate a user, where the loginid and password are available as request parameters. In case the authentication is successful, it should setup a new session and store the user's information in the session before forwarding to home.jsp, which displays the user's information like full name, address, etc.


index.jsp


<html>
<head>
<title>EX-18</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:300px;
left:5in;
border-style:solid;
}
</style>
</head>

<body>

<div class="abc"  id="f1">
<br>
<form method="POST" action="/Ex18/bipinrupadiya.blogspot.com">
<table align="center">
<tr>
<td>User Name : </td>
<td><input type="text" name="txtUsr"></td>
</tr>
<tr>
<td>Password :</td>
<td><input type="password" name="txtPwd"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="submit" value="Login">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>

home.jsp


<html>
<head>
<title>EX-18</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:300px;
left:5in;
border-style:solid;
}
</style>
</head>

<body>
<%
        HttpSession sessi=request.getSession();
%>
<div class="abc"  id="f1">

<center>
<h1><font color="#FFFFFF">Welcome <%= session.getAttribute("sFName") %> ...!</font></h1>
<table border="1" cellPadding="5px">
<tr>
<td>Name :</td>
<td>
<%= session.getAttribute("sFName") %>&nbsp;
<%= session.getAttribute("sMName") %>&nbsp;
<%= session.getAttribute("sLName") %>
</td>
</tr>
<tr>
<td>Date of Birth :</td>
<td><%= session.getAttribute("sDOB") %></td>
</tr>
<tr>
<td>Adsress :</td>
<td><%= session.getAttribute("sAddress") %></td>
</tr>

</table>
<%session.invalidate();%>
<br>
<a href="index.jsp"> Logout </a>

</div>
</body>
</html>

Ex18.java



import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Ex18 extends HttpServlet
{
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
    {

response.setContentType("text/html");
        PrintWriter out=response.getWriter();

        String usr=request.getParameter("txtUsr");
        String pwd=request.getParameter("txtPwd");
       
        if( usr.equals("bipin") && pwd.equals("rupadiya") )
        {
   String myDiv;
out.println("<html><body><form>");
myDiv="<div style='background:#ababff; position:absolute; ";
myDiv=myDiv+"top:2in; hieght:200px; width:300px;left:5in;border-style:solid'>";
out.println(myDiv);
out.println("<form><table cellpadding'2px'>");
            out.println("<tr><td>First Name :</td><td><input type='text' name='txtFName' ></td></tr>");
out.println("<tr><td>MiddleName : </td><td><input type='text' name='txtMName' ></td></tr>");
out.println("<tr><td>Last Name : </td><td><input type='text' name='txtLName' ></td></tr>");
            out.println("<tr><td>Date of Birth : </td><td><input type='text' name='txtDOB' ></td></tr>");
out.println("<tr><td>Address : </td><td><input type='text' name='txtAddress'></td></tr>");
            out.println("<tr><td colspan='2'><input type='submit' value='OK'>");
out.println("<input type='reset' value='Clear'></td></tr>");
out.println("</td></form></div></body></html>");
}
        else
        {
            response.sendRedirect("index.jsp");
        }
    }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
    {
HttpSession session=request.getSession();
session.setAttribute("sFName",request.getParameter("txtFName"));
session.setAttribute("sMName",request.getParameter("txtMName"));
session.setAttribute("sLName",request.getParameter("txtLName"));
session.setAttribute("sDOB",request.getParameter("txtDOB"));
session.setAttribute("sAddress",request.getParameter("txtAddress"));
response.sendRedirect("home.jsp");
    }  
}


postheadericon 17. Develop a Servlet which looks for cookies for username and password, and forwards to a home.jsp in case the cookies are valid and forwards to login.jsp, in case the cookies are not found or the cookies are not valid





index.jsp


<html>
<head>
<title>EX-17</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:300px;
left:5in;
border-style:solid;
}
</style>
</head>

<body>

<div class="abc"  id="f1">
<br>
<form method="POST" action="/Ex17/bipinrupadiya.blogspot.com">
<table align="center">
<tr>
<td>User Name : </td>
<td><input type="text" name="txtUsr"></td>
</tr>
<tr>
<td>Password :</td>
<td><input type="password" name="txtPwd"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="checkbox" name="chkRM">
Remember Me
</td>
</tr>

<tr>
<td colspan=2 align=center>
<input type="submit" value="Login">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>

home.jsp


<html>
<head>
<title>EX-17</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:300px;
left:5in;
border-style:solid;
}
</style>
</head>
<body>
<div class="abc"  id="f1">
<br>
<center>
<h1>WELCOME
<br>
</div>
</body>
</html>



Ex17.java


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Ex17 extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String usr = request.getParameter("txtUsr");
String pwd = request.getParameter("txtPwd");
String RM  = request.getParameter("chkRM");

if (RM != null)
{
Cookie cookie = new Cookie(usr,pwd);
cookie.setMaxAge(60*60*24*365);// 1 Year
response.addCookie(cookie);
}
Cookie[] cookies = request.getCookies();
if (cookies != null)
{
//Cookie("bipin","rupadiya");
//Cookie(usr,pwd);
String cPwd="x";
for(int i=0; i<cookies.length; i++) //user check
{
Cookie cookie = cookies[i];
if (usr.equals(cookie.getName()))
{
cPwd=cookie.getValue();
break;
}
}
if(cPwd.equals(pwd))//password check
{
response.sendRedirect("home.jsp");
}
else
{
//out.println("<script>alert('User Name or Password is incorrect. Please Try Again');location.href='login.jsp';</script>");
response.sendRedirect("index.jsp");
}
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
doGet(request,response);
}
}


postheadericon 15. Assume that we have got three pdf files for the MCA-1 Syllabus, MCA-2 Syllabus and MCA-3 Syllabus respectively, Now write a Servlet which displays the appropriate PDF file to the client, by looking at a request parameter for the year (1, 2 or 3).


Index.html


<html>
<head>
<title>EX-15: WTAD : www.bipinrupadiya.com</title>
</head>
<body>
<center>
<FORM action="/Ex15/bipinrupadiya.blogspot.com">
Select MCA Syllabus : <select size=1 name="MCA">
<option value="MCA-1">MCA1</option>
<option value="MCA-2">MCA2</option>
<option value="MCA-3">MCA3</option>
</select>
<INPUT TYPE="SUBMIT" value="Show" >
</FORM>
</center>
</body>
</html>

Servlet


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;


@WebServlet(
name="WTAD",
urlPatterns={"/Ex15","/bipinrupadiya.blogspot.com"}
)
public class ShowPDF extends HttpServlet
{
  public void doGet(HttpServletRequest request, HttpServletResponse response)throws
ServletException,IOException
{
String sem = request.getParameter("MCA");
response.setContentType("application/pdf");
response.sendRedirect("/"+sem+".pdf");
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
doGet(request,response);
}
}


NOTE: Put Three .pdf file on application's root directory (MCA-1.pdf, MCA-2.pdf, MCA-3.pdf)







Categories

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.