ajwt-part2
TRANSCRIPT
-
7/24/2019 ajwt-part2
1/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 42
XML PROGRAMS
-
7/24/2019 ajwt-part2
2/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 43
AIM: Write an basic XML program.
PROGRAM:
Basic1.xml
ABC
0501
HYDERABAD
DEF
0502
VIJAYAWADA
GHI
0503
GUNTUR
JKL
0504
VIZAG
-
7/24/2019 ajwt-part2
3/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 44
OUTPUT:
-
7/24/2019 ajwt-part2
4/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 45
AIM: Write an XML program using Internal DTD.
PROGRAM:
Internaldtd.xml
]>
ABC 0501 HYDERABAD
DEF 0502 VIJAYAWADA
GHI
0503 GUNTUR
JKL 0504 VIZAG
-
7/24/2019 ajwt-part2
5/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 46
OUTPUT:
-
7/24/2019 ajwt-part2
6/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 47
AIM: Write an XML program Using External DTD.
First.dtd
Sample1.xml
ABC
0501
HYDERABAD
DEF
0502
VIJAYAWADA
GHI
0503
GUNTUR
JKL
0504 VIZAG
-
7/24/2019 ajwt-part2
7/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 48
OUTPUT:-
-
7/24/2019 ajwt-part2
8/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 49
Aim:-Write an XML program Using XMLSchema
student.xsd:
-
7/24/2019 ajwt-part2
9/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 50
student.xml:
09A71A0501
A
ANUSHA
Venkateswara
Rao
software engineering
1ST Year
3215/144
B.R.Nagar1
Hyderabad
9988776655
09A71A0501
B
KISHORE
Venkateswara
B
software engineering
1st Year
door no 603/n
Recoloney
Vijayawada
9966332255
08A01D2503
-
7/24/2019 ajwt-part2
10/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 51
OUTPUT:-
-
7/24/2019 ajwt-part2
11/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 52
AIM:- Write an XML program Using CSS.
PROGRAM:
xmlstyle.css
student_details
{
background-color: skyblue;
width: 100%;
}
std_name
{
display: block;
color: green;
font-size: 20pt;
}
std_no
{
color: #FF0000;
font-size: 20pt;
margin-left: 10pt;
}
std_addr
{
color: #0000FF;
font-size: 20pt;
margin-left: 10pt;
}
Basic2.xml
ABC 0501 HYDERABAD
DEF 0502 VIJAYAWADA
GHI 0503 GUNTUR
-
7/24/2019 ajwt-part2
12/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 53
JKL 0504 VIZAG
OUTPUT:
-
7/24/2019 ajwt-part2
13/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 54
AIM: Write an XML program Using XSLT.
PROGRAM:
simple.xsl
--
--
(PLACE)
Basic3.xml
UDAY
3501
GUNTUR
GOOD and SATISFACTORY
MAHESH
3502
VIJAYAWADA
WELL AND GOOD
-
7/24/2019 ajwt-part2
14/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 55
OUTPUT:
-
7/24/2019 ajwt-part2
15/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 56
JAVA BEANS
-
7/24/2019 ajwt-part2
16/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 57
Aim:- Developing a Simple Bean Using the BDK:
This section presents an example that shows how to develop a simple Bean andconnect it to other components via the BDK. Our new component is called the Colors Bean.It appears as either a rectangle or ellipse that is filled with a color. A color is chosen at
random when the Bean begins execution. A public method can be invoked to change it. Eachtime the mouse is clicked on the Bean, another random color is chosen. There is oneboolean read/write property that determines the shape. The BDK is used to lay out anapplication with one instance of the Colors Bean and one instance of the OurButton Bean.The button is labeled Change. Each time it is pressed, the color changes.DEVELOPMENT
USING JAVA
Create a New Bean
Here are the steps that you must follow to create a new Bean:
1. Create a directory for the new Bean.
2. Create the Java source file(s).
3. Compile the source file(s).4. Create a manifest file.
5. Generate a JAR file.
6. Start the BDK.
7. Test.
The following sections discuss each of these steps in detail.
Create a Directory for the New Bean You need to make a directory for the Bean. Tofollow along with this example, create c:\bdk\demo\sunw\demo\colors . Then change to that
directory. The Colors and OurButton Beans Create the Source File for the New Bean Thesource code for the Colors component is shown in the following listing. It is located in the fileColors.java. The import statement at the beginning of the file places it in the packagenamed sunw.demo.colors. Recall from Chapter 9 that the directory hierarchy correspondsto the package hierarchy. Therefore, this file must be located in a subdirectory namedsunw\demo\colors relative to the CLASSPATH environment variable. The color of thecomponent is determined by the private Color variable color, and its shape is determined bythe private boolean variable rectangular. The constructor defines an anonymous inner classthat extends MouseAdapter and overrides its mousePressed( ) method. The change( )method is invoked in response to mouse presses. The component is initialized to arectangular shape of 200 by 100 pixels. The change( ) method is invoked to select a random
color and repaint the component. The getRectangular( ) and setRectangular( ) methodsprovide access to the one property of this Bean. The change( ) method calls randomColor() to choose a color and then calls repaint( ) to make the change visible. Notice that thepaint( ) method uses the rectangular and color variables to determine how to present theBean.
-
7/24/2019 ajwt-part2
17/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 58
// A simple Bean.
package sunw.demo.colors;
import java.awt.*;
import java.awt.event.*;
public class Colors extends Canvas
{
transient private Color color;
private boolean rectangular;
public Colors()
{
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent me)
{
change();
}
}
rectangular = false;
setSize(200, 100);
change();
}
public boolean getRectangular()
{
return rectangular;
}
public void setRectangular(boolean flag)
{
this.rectangular = flag;
repaint();
}
public void change()
{
color = randomColor();
repaint();
}
private Color randomColor()
{
int r = (int)(255*Math.random());
int g = (int)(255*Math.random());
int b = (int)(255*Math.random());
return new Color(r, g, b);
}public void paint(Graphics g)
-
7/24/2019 ajwt-part2
18/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 59
{
Dimension d = getSize();
int h = d.height;
int w = d.width;
g.setColor(color);
if(rectangular) {
g.fillRect(0, 0, w-1, h-1);
}
else {
g.fillOval(0, 0, w-1, h-1);
}
}
}
Compile the Source Code for the New Bean Compile the source code to create a class file.
Type the following:
javac Colors.java.
Create a Manifest File You must now create a manifest file. First, switch to thec:\bdk\demo directory. This is the directory in which the manifest files for the BDK demosare located. Put the source code for your manifest file in the file colors.mft.
Type the following:Name: sunw/demo/colors/Colors.class
Java-Bean: True
This file indicates that there is one .class file in the JAR file and that it is a Java BeanNotice that the Colors.class file is in the package sunw.demo.colors and in thesubdirectory sunw\demo\colors relative to the current directory. Generate a JAR File Beansare included in the ToolBox window of the BDK only if they are in JAR files in the directoryc:\bdk\jars. These files are generated with the jar utility.
Type the following:jar cfm ..\jars\colors.jar colors.mft sunw\demo\colors\*.class
This command creates the file colors.jar and places it in the directory c:\bdk\jars.
Start the BDK Change to the directory c:\bdk\beanbox and type run. This causes theBDK to start. You should see three windows, titled ToolBox, BeanBox, and Properties. TheToolBox window should include an entry labeled Colors for your new Bean. Create anInstance of the Colors Bean After you complete the preceding steps, create an instance ofthe Colors Bean in the BeanBox window. Test your new component by pressing the mouseanywhere within its borders. Its color immediately changes. Use the Properties window to
change the rectangular property from false to true. Its shape immediately changes.
-
7/24/2019 ajwt-part2
19/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 60
Create and Configure an Instance of the OurButton Bean Create an instance of theOurButton Bean in the BeanBox window. Then follow these steps:
1. Go to the Properties window and change the label of the Bean to Change. You shouldsee that the button appearance changes immediately when this property is changed.
2. Go to the menu bar of the BeanBox and select Edit | Events | action | actionPerformed.3. Move the cursor so that it is inside the Colors Bean display area, and click the left mousebutton. You should see the Event Target Dialog dialog box.
4. The dialog box allows you to choose a method that should be invoked when this button isclicked. Select the entry labeled change and click the OK button.You should see a messagebox appear very briefly, stating that the tool isGenerating and compiling adaptor class.
5. Click on the button. You should see the color change. You might want to experiment withthe Colors Bean a bit before moving on.
Output:
-
7/24/2019 ajwt-part2
20/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 61
SERVLET PROGRAMS
-
7/24/2019 ajwt-part2
21/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 62
DATABASE screen shots:-
Users1 Table:-
Orders Table:-
-
7/24/2019 ajwt-part2
22/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 63
Reg.javaimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;public class Reg extends HttpServlet
{public void doPost(HttpServletRequest req,HttpServletResponse res) throwsServletException,IOException{res.setContentType("text/html");PrintWriter out=res.getWriter();out.print("");String name=req.getParameter("txt1");String fname=req.getParameter("txt2");String age=req.getParameter("txt3");String usr=req.getParameter("usr");String pwd1=req.getParameter("Pass2");
String gender=req.getParameter("rdo1");String hobbies1=req.getParameter("chk1");String hobbies2=req.getParameter("chk2");String hobbies3=req.getParameter("chk3");String hobbies4=req.getParameter("chk4");String hobbies=hobbies1+hobbies2+hobbies3+hobbies4;String email=req.getParameter("mail");String addres=req.getParameter("adrs");try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con=DriverManager.getConnection("jdbc:odbc:oracle","system","manager");Statement stmt=con.createStatement();
String sqlstmt="select * from users1";ResultSet rs=stmt.executeQuery(sqlstmt);int flag=0;
while(rs.next()) {if(name.equals(rs.getString(4)) || email.equals(rs.getString(8)))
{flag=1;}
}if(flag==1) {out.println("Sorry INVALID ID or ALREADY EXITS try with
New ID
");out.println("press REGISTER to RETRY");}Else {Statement st=con.createStatement();st.executeUpdate("insert into users1 values ('"+name+"','"+fname+"','"+age+"', '"+usr+"','"+
pwd1 +"','"+gender+"','"+hobbies+"','"+email+"','"+addres+"')");out.print(" alert('Successfully Registers') ") ;}
rs.close();stmt.close();con.close();}
catch(Exception ex) {out.print("--Error occured while Registering--");} } }
-
7/24/2019 ajwt-part2
23/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 64
Login.java
import java.sql.*;import java.io.*;import java.util.*;import javax.servlet.*;
import javax.servlet.http.*;public class Login extends HttpServlet{public void doPost(HttpServletRequest req,HttpServletResponse res)throwsServletException,IOException{res.setContentType("text/html");PrintWriter out=res.getWriter();out.println("");String uname=req.getParameter("text1");String pwd1=req.getParameter("pwd");try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con=DriverManager.getConnection("jdbc:odbc:oracle","system","manager");PreparedStatement pst=con.prepareStatement("select uname,pwd from users1");ResultSet rs=pst.executeQuery();int flag=0;
while(rs.next()){if(rs.getString(1).equals(uname) && rs.getString(2).equals(pwd1))
{flag=1;}
}if(flag==0){out.println("SORRY INVALID ID TRY AGAIN ID
");out.println("For ReTry - Click Here
");out.println("For Registration - ClickHere
");out.println("Forget UserName & Password - ClickHere");}else{
out.println("VALID LOGIN ID");out.println("WELCOME "+uname+"
");out.println("--To view and update your ProfileClick Here
");out.println("--------------------------------");}out.println("");}catch(Exception ex){out.println(-----ERROR OCCURRED----);}out.close();}
}
-
7/24/2019 ajwt-part2
24/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 65
Forget.java
import java.sql.*;import java.io.*;import java.util.*;import javax.servlet.*;
import javax.servlet.http.*;public class Forget extends HttpServlet{public void doPost(HttpServletRequest req,HttpServletResponse res)throwsServletException,IOException{res.setContentType("text/html");PrintWriter out=res.getWriter();out.println("");out.println("");String mail=req.getParameter("email1");try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con=DriverManager.getConnection("jdbc:odbc:oracle","system","manager");PreparedStatement pst=con.prepareStatement("select * from users1 where email=?");pst.setString(1,mail);ResultSet rs=pst.executeQuery();String name,uname1,pwd1;if(rs.next()){uname1=rs.getString(4);pwd1=rs.getString(5);name=rs.getString(1);
out.print("VALID ID");out.println("--------------------------------");out.println(" WELCOME -
"+name+"");out.println(" Your Login Details are -");out.println("User Name - "+uname1+"");out.println("Password - "+pwd1+"");out.println("--------------------------------");}else{out.println("SORRY INVALID ID TRY AGAIN
");out.println("--------------------------------");out.println("For Registration - Click Here
");out.println("For RETRY- Click Here ");out.println("--------------------------------");}out.println("");}catch(Exception ex){out.print(-----ERROR OCCURRED--------);}out.close();}}
-
7/24/2019 ajwt-part2
25/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 66
Profile.javaimport java.sql.*;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;
public class Profile extends HttpServlet {public void doPost(HttpServletRequest req,HttpServletResponse res)throwsServletException,IOException {res.setContentType("text/html");PrintWriter out=res.getWriter();out.println("");out.println("");String uname=req.getParameter("name");try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con=DriverManager.getConnection("jdbc:odbc:oracle","system","manager");PreparedStatement pst=con.prepareStatement("select * from users1 where uname=?");
pst.setString(1,uname);ResultSet rs=pst.executeQuery();if(rs.next()) {
out.println("------------------------------------------------");out.println(" User's Profile ");out.println("");out.println("User Name:-");out.println("Name:-");out.println("Father Name:-"+rs.getString(2)+"");
out.println("Age:-");out.println("Password:-");out.println("Gender:-"+rs.getString(6)+"");out.println("Address:-"+rs.getString(9)+"");out.println("");out.println("");out.println("------------------------------------------------");}
else {
out.println("SORRY INVALID ID TRY AGAIN ID
");out.println("For ReTry - Click Here
");out.println("For Registration - ClickHere
");out.println("Forget UserName & Password - ClickHere");}out.println("");out.println("");
}catch(Exception ex){out.print(---Error Occurred while displaying User Profile -------);
}out.close();}}
-
7/24/2019 ajwt-part2
26/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 67
Updateprof.java
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;public class Updateprof extends HttpServlet
{public void doGet(HttpServletRequest req,HttpServletResponse res) throws
ServletException,IOException{res.setContentType("text/html");PrintWriter out=res.getWriter();out.print("");String uname=req.getParameter("uname");String name=req.getParameter("name");String age=req.getParameter("age1");String pwd1=req.getParameter("pwd");String addr=req.getParameter("select1");
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection
con=DriverManager.getConnection("jdbc:odbc:oracle","system","manager");Statement st=con.createStatement();st.executeUpdate("update users1 set
name='"+name+"',age='"+age+"',pwd='"+pwd1+"',address='"+addr+"' where
uname='"+uname+"'");out.print(" alert('Updated Successfully') ") ;st.close();con.close();}
catch(Exception ex){out.print("--Error occured while Updating--");}}
}
-
7/24/2019 ajwt-part2
27/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 68
Orders.javaimport java.sql.*;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;
import java.text.*;import java.util.*;import java.util.Date;public class Orders extends HttpServlet {public void service(HttpServletRequest req,HttpServletResponse resp) throwsServletException,IOException {PrintWriter pw=resp.getWriter();pw.println("");String id=req.getParameter("uname");String pwd=req.getParameter("pwd");String title=req.getParameter("title");String count1=req.getParameter("no");
String price=req.getParameter("cost");String cost=req.getParameter("tcost");try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con=DriverManager.getConnection("jdbc:odbc:oracle","system","manager");Statement stmt=con.createStatement();String sqlstmt="select uname,pwd,address from users1";ResultSet rs=stmt.executeQuery(sqlstmt);int flag=0,amount,x;while(rs.next()) {
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2))){
flag=1;} }
if(flag==0) {pw.println("SORRY INVALID ID TRY AGAIN ID
");pw.println("press HERE to RETRY");}else {Date today = new Date();Format formatter1;Format formatter2;formatter1 = new SimpleDateFormat("dd-MMM-yy");String s1 = formatter1.format(today);
formatter2 = new SimpleDateFormat("HH:mm:ss");String s2 = formatter2.format(today);Statement stmt1=con.createStatement();stmt1.executeUpdate("insert into orders values('"+id+"','"+title+"', '"+count1+"',
'"+price+"','"+cost+"','"+s1+"','"+s2+"')");pw.println("YOUR ORDER has taken
");pw.println("Continue Shopping- Click Here
");}pw.println("");con.close();}
catch(Exception e) {resp.sendError(500,e.toString());} } }
-
7/24/2019 ajwt-part2
28/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 69
web.xml
a1Logina1/servlet1a12Profilea12/servletprofile12a123Rega123/Servletreg1a1234Forgeta1234/Servletreg1a12345Ordersa12345/conforder1a123456Updateprofa123456/update
-
7/24/2019 ajwt-part2
29/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 70
OUTPUTS
-
7/24/2019 ajwt-part2
30/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 71
Home Page:-
Branch Page:-
-
7/24/2019 ajwt-part2
31/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 72
Registration Page with INVALID data:-
-
7/24/2019 ajwt-part2
32/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 73
Registration Page with VALID date:-
-
7/24/2019 ajwt-part2
33/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 74
Login Screen - INVALID Data:-
-
7/24/2019 ajwt-part2
34/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 75
Login Screen - VALID Data:-
-
7/24/2019 ajwt-part2
35/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 76
Updating Profile:-
-
7/24/2019 ajwt-part2
36/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 77
-
7/24/2019 ajwt-part2
37/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 78
Forget Password with INVALID Mail-ID:-
-
7/24/2019 ajwt-part2
38/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 79
Forget Password with VALID Mail-ID :-
-
7/24/2019 ajwt-part2
39/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 80
Catalog Page:-
-
7/24/2019 ajwt-part2
40/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 81
Cart Page with INVALID ID:-
-
7/24/2019 ajwt-part2
41/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 82
Cart Page with VALID ID:-
-
7/24/2019 ajwt-part2
42/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 83
Data in Tables:-
Users1 Table:-
Orders Table:-
-
7/24/2019 ajwt-part2
43/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 84
JSP PROGRAMS
-
7/24/2019 ajwt-part2
44/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 85
Registration Page Using JSP :-
Reg.html
function validate(){
var age=document.myform.txt3.value;var uname=document.myform.usr.value;
if(document.myform.txt1.value==){alert(Enter your Name);return false;}
else if(age==){
alert(Enter your Age);return false;}
else if(isNaN(age)){alert(Enter Numeric Value in Age);return false;}
else if(age100){alert(Enter Valid Age);return false;}
else if(uname==){
alert(Enter UserName);return false;}
else if(uname.length
-
7/24/2019 ajwt-part2
45/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 86
}else if(document.myform.Pass1.value!=document.myform.Pass2.value)
{alert(Passwords Should Match);return false;
}else if(document.myform.chk1.checked==false || document.myform.chk2.cheked==false
|| document.myform.chk3.cheked==false || document.myform.chk4.cheked==false){
alert(Enter your Hobbies);return false;}
else if(document.myform.mail.value==){
alert(Enter E-Mail);return false;}
else if(document.myform.accept.checked==false){alert(verify check box aggrement);
return false;}
}
* marks are mandatory
Enter Name*:-
Father Name:-
Age*
Enter User Name*:-
Enter Password*:-
-
7/24/2019 ajwt-part2
46/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 87
Confirm Password*:-
Gender* male
femaleHobbies* Playing
Games Reading Books Watching Movies Cooking
E-mail*
Address I
accept the terms
insert.jsp
-
7/24/2019 ajwt-part2
47/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 88
String hobbies1=request.getParameter(chk1);String hobbies2=request.getParameter(chk2);String hobbies3=request.getParameter(chk3);String hobbies4=request.getParameter(chk4);String hobbies=hobbies1+hobbies2+hobbies3+hobbies4;String email=request.getParameter(mail);String addres=request.getParameter(adrs);Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
Connection con=DriverManager.getConnection(jdbc:odbc:oracle,system,manager);out.print(---Connected ORACLE---);try {
Statement stmt=con.createStatement();String sqlstmt=select * from users1;ResultSet rs=stmt.executeQuery(sqlstmt);int flag=0;
while(rs.next()){if(name.equals(rs.getString(4)) || email.equals(rs.getString(8)))
{flag=1;}
}if(flag==1){
out.println(Sorry INVALID ID or ALREADYEXITS try with New ID
);out.println(press REGISTER toRETRY);}else{
Statement st=con.createStatement();st.executeUpdate(insert into users1 values (+name+,+fname+,+age+,
+usr+,+ pwd1+,+gender+,+hobbies+,+email+,+addres+));out.print( alert(Successfully Registers) ) ;
}rs.close();stmt.close();con.close();
}catch(Exception ex) {out.print(--Error occurred while Registering--);}
%>
-
7/24/2019 ajwt-part2
48/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 89
OUTPUT:-
Registration Page with VALID Data:-
-
7/24/2019 ajwt-part2
49/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 90
Registration Page with IN-VALID Data:-
-
7/24/2019 ajwt-part2
50/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 91
Login Page Using JSP :-Login.html
log in
function Validate(){var usr=document.forms[0].elements[0].value;var pwd=document.forms[0].elements[1].value;
if(usr==""){
alert("Enter User Name");return false;
}else if(pwd==""){
alert("Enter Password");return false;}else{redirect(welcome.html);}
}
User Name -
Password -
CREATE NEW ACCOUNT -- Click Here
-
7/24/2019 ajwt-part2
51/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 92
Forget Password -- Click Here
function validate()
login.jsp
-
7/24/2019 ajwt-part2
52/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 93
Here
");out.println("--------------------------------");}out.println("");
}
catch(Exception ex){
out.println("----Error Occured while Retriving------");}out.close();
%>
-
7/24/2019 ajwt-part2
53/54
Roll No: Advanced Java & Web Technology Lab
NALANDA INSTITUTE OF ENGINEERING & TECHNOLOGY Page- 94
OUTPUT:-
Login Page with VALID Data:-
-
7/24/2019 ajwt-part2
54/54
Roll No: Advanced Java & Web Technology Lab
Login Page with IN-VALID Data:-