Sie sind auf Seite 1von 7

Files Required

reg1.html
reg2.html
reg3.html

MVC

DBUtil.java
RegAction1.java
RegAction2.java
RegAction3.java
SDControllerServlet.java
SDModel.java
SummaryAction.java
URIConstants.java
UserTo.java

reg1.html
<html>
<head>
<title>register@JAVA LEARNING CENTER</title>
<head>
<body bgcolor="PINK">
<center>
<font color="GREEN" size="6" face="MS
ROMMAN">JAVA LEARNING
CENTER</font><br>
<u><font color="blue" size="5">Registrationpart1</font></u>
<form action="/reg1.sd" method="get">
<table border="9">
<tr>

results.jsp
summary.jsp
WEB.XML
oracle.TXT

MVC PIVII

<td><font color="sky blue" size="5" face="bold">


First Name</font></td>
<td><input type="text" name="fname"/></td>
</tr>
<tr>
<td><font color="green" size="5" face="bold">
Last Name</font></td>
<td><input type="text" name="lname"/></td>
</tr>
<tr>
<td colspan="2" align="center"> <input
type="submit" value= "Continue..."/></td>
</tr>
</table></form></body></html>

reg2.html
<html>
<head>
<title>register@JAVA LEARNING CENTER</title>
<head>
<body bgcolor="PINK">
<center>
<font color="GREEN" size="6" face="MS
ROMMAN">JAVA LEARNING CENTER</font><br>
<u><font color="blue" size="5">Registrationpart2</font></u>
<form action="/reg2.sd" method="get">
<table border="9">
<tr>

<td><font color="Yellow" size="5" face="bold">


Email</td>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td><font color="Red" size="5" face="bold">
Phone</td>
<td><input type="text" name="phone"/></td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit"
value= "Continue..."/></td>
</tr>
</table></form></body></html>

reg3.html
<html>
<head>
<title>register@JAVA LEARNING CENTER</title>
<head>
<body bgcolor="#034562">
<center>
<font color="GREEN" size="6" face="MS
ROMMAN">JAVA LEARNING CENTER</font><br>
<u><font color="RED" size="5">Registrationpart3</font></u>
<form action="/reg3.sd" method="get">
<table border="9">
<tr>

<td><font color="orange" size="5" face="bold">city</td>


<td><input type="text" name="city"/></td>
</tr>
<tr>
<td><font color="pink" size="5" face="bold">
State</td>
<td><input type="text" name="state"/></td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit"
value= "Continue..."/></td>
</tr>
</table></form></body></html>

DBUtil.java

package com.javasree.user.util;

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin
:@rajiv:1521:javasree","scott","tiger");
return con;
}
public static void cleanup(Connection
con,Statement st)
{
try
{
if(st!=null)
st.close();
if(con!=null)
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

import java.sql.*;
import java.util.*;
public class DBUtil
{
public static Connection getMySqlConnection() throws
Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://rajiv/
pro","rajiv","");
return con;
}
public static Connection getOracleConnection() throws
Exception
{

MVC II

RegAction1.java

package com.javasree.user.web;

{
String fn=req.getParameter("fname");
String ln=req.getParameter("lname");
HttpSession ses=req.getSession();
UserTo uto=new UserTo();
uto.setFname(fn);
uto.setLname(ln);
ses.setAttribute("UTO",uto);
Cookie c1=new Cookie("FN",fn);
Cookie c2=new Cookie("LN",ln);
res.addCookie(c1);
res.addCookie(c2);

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.javasree.user.to.*;
public class RegAction1
{
public void process(HttpServletRequest
req,HttpServletResponse res) throws
ServletException,IOException
}
}
RegAction2.java

package com.javasree.user.web;

String em=req.getParameter("email");
String ph=req.getParameter("phone");

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.javasree.user.to.*;

HttpSession ses=req.getSession();
UserTo uto=(UserTo)ses.getAttribute("UTO");
uto.setEmail(em);
uto.setPhone(ph);
ses.setAttribute("UTO",uto);
Cookie c1=new Cookie("EM",em);
Cookie c2=new Cookie("PH",ph);
res.addCookie(c1);
res.addCookie(c2);
}

public class RegAction2


{
public void process(HttpServletRequest
req,HttpServletResponse res) throws
ServletException,IOException
{
}

RegAction3.java

package com.javasree.user.web;

{
String ci=req.getParameter("city");
String st=req.getParameter("state");
HttpSession ses=req.getSession();
UserTo uto=(UserTo)ses.getAttribute("UTO");
uto.setCity(ci);
uto.setState(st);
ses.setAttribute("UTO",uto);
Cookie c1=new Cookie("CI",ci);
Cookie c2=new Cookie("ST",st);
res.addCookie(c1);
res.addCookie(c2);
}
}

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.javasree.user.to.*;
public class RegAction3
{
public void process(HttpServletRequest
req,HttpServletResponse res) throws
ServletException,IOException

SDControllerServlet.java

package com.javasree.user.web;

{
RegAction2 ra2=new RegAction2();
import javax.servlet.*;
ra2.process(req,res);
import javax.servlet.http.*;
RequestDispatcher
import java.io.*;
rd=req.getRequestDispatcher("/reg3.html");
import com.javasree.user.util.*;
rd.forward(req,res);
}
public class SDControllerServlet extends HttpServlet
if(uri.equals(URIConstants.REG3))
{
{
public void service(HttpServletRequest
RegAction3 ra3=new RegAction3();
req,HttpServletResponse res) throws
ra3.process(req,res);
ServletException,IOException
RequestDispatcher
{
rd=req.getRequestDispatcher("/summary.jsp");
String uri=req.getRequestURI();
rd.forward(req,res);
if(uri.equals(URIConstants.REG1))
}
{
if(uri.equals(URIConstants.SUMMARY))
RegAction1 ra1=new RegAction1();
{
ra1.process(req,res);
SummaryAction sa=new SummaryAction();
RequestDispatcher
sa.process(req,res);
rd=req.getRequestDispatcher("/reg2.html");
RequestDispatcher
rd.forward(req,res);
rd=req.getRequestDispatcher("/results.jsp");
}
rd.forward(req,res);
else if(uri.equals(URIConstants.REG2))
}
}
}
SDModel.java
package com.javasree.user.model;
x=st.executeUpdate("insert into user99
values(uid_seq.nextval"+",'"+uto.getFname()+"','"+uto.getLname()
import java.sql.*;
+"','"+uto.getEmail()+"','"+uto.getPhone()+"','"+uto.getCity()
import java.util.*;
+"','"+uto.getState()+"')");
import com.javasree.user.util.*;
}
import com.javasree.user.to.*;
catch(Exception e)
{
public class SDModel
e.printStackTrace();
{
}
public int registerUser(UserTo uto)
finally
{
{
int x=0;
try
Connection con=null;
{
Statement st=null;
DBUtil.cleanup(con,st);
try
}
{
catch(Exception e1)
con=DBUtil.getOracleConnection();
{
st=con.createStatement();
e1.printStackTrace();
}
}

MVC

III

return x;
}
SummaryAction.java

package com.javasree.user.web;

HttpSession ses=req.getSession();
UserTo uto=(UserTo)ses.getAttribute("UTO");
SDModel sd=new SDModel();
int x=sd.registerUser(uto);
String msg=null;
if(x==1)
{
msg="Successful";
}
else
{
msg="!REGISTRATION FAILED !";
}
ses.setAttribute("MSG",msg);
}}

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.javasree.user.to.*;
import com.javasree.user.model.*;
public class SummaryAction
{
public void process(HttpServletRequest
req,HttpServletResponse res) throws
ServletException,IOException

URIConstants.java

package com.javasree.user.util;
public interface URIConstants
{
String REG1="/reg1.sd";

String REG2="/reg2.sd";
String REG3="/reg3.sd";
String SUMMARY="/summary.sd";
}
UserTo.java

package com.javasree.user.to;
public class UserTo
{
private int userid;
private String fname;
private String lname;
private String email;
private String phone;
private String city;
private String state;
public void setUserid(int userid)
{
this.userid=userid;
}
public int getUserid()
{
return this.userid;
}
public void setFname(String fname)
{
this.fname=fname;
}
public String getFname()
{
return this.fname;
}
public void setLname(String lname)
{
this.lname=lname;
}
public String getLname()
{
return this.lname;

public void setEmail(String email)


{
this.email=email;
}
public String getEmail()
{
return this.email;
}
public void setPhone(String phone)
{
this.phone=phone;
}
public String getPhone()
{
return this.phone;
}
public void setCity(String city)
{
this.city=city;
}
public String getCity()
{
return this.city;
}
public void setState(String state)
{
this.state=state;
}
public String getState()
{
return this.state;
}
}

MVC IV

results.jsp
<%@page import="com.javasree.user.to.*"%>
else if(ck[i].getName().equals("CI"))
{
<html>
cuto.setCity(ck[i].getValue());
<head>
}
<title>register@JAVA LEANING CENTER</title>
else if(ck[i].getName().equals("ST"))
<head>
{
<body bgcolor="ORANGE">
cuto.setState(ck[i].getValue());
<center>
}
<h1>ONLINE REGISTRATION FOR JAVA
}
LEARNIG CENTER</h1>
%>
<font color="RED" size="6" face="MS
<table border="1">
ROMMON">JAVA LEARNING
<tr>
CENTER</font><br>
<td>First Name</td>
<u><font color="blue" size="5">Registration<td><%=cuto.getFname()%></td>
status</font></u><br>
</tr>
<tr>
<%
<td>Last Name</td>
UserTo
<td><%=cuto.getLname()%></td>
cuto=(UserTo)session.getAttribute("UTO");
</tr>
Cookie ck[]=request.getCookies();
<tr>
for(int i=0;i<ck.length;i++)
<td>Email</td>
{
<td><%=cuto.getEmail()%></td>
if(ck[i].getName().equals("FN"))
</tr>
{
<tr>
cuto.setFname(ck[i].getValue());
<td>Phone</td>
}
<td><%=cuto.getPhone()%></td>
else if(ck[i].getName().equals("LN"))
</tr>
{
<tr>
cuto.setLname(ck[i].getValue());
<td>City</td>
}
<td><%=cuto.getCity()%></td>
else if(ck[i].getName().equals("EM"))
</tr>
{
<tr>
cuto.setEmail(ck[i].getValue());
<td>State</td>
}
<td><%=cuto.getState()%></td>
else if(ck[i].getName().equals("PH"))
</tr>
{
</table>
cuto.setPhone(ck[i].getValue());
<%=session.getAttribute("MSG")%><br>
}
<a href="reg1.html">Go to 1st page</a>
</body> </html>
WEB.XML
oracle.TXT
create table user99
<web-app>

MVC V

<servlet>
<servlet-name>controller</servlet-name>
<servletclass>com.javasree.user.web.SDControllerServlet</servletclass>
</servlet>
<servlet-mapping>
<servlet-name>controller</servlet-name>

(
userid int primary key,
fname char(15),
lname char(15),
email char(15),
phone char(15),
city char(15),
state char(15));

create sequence uid_seq


increment by 1;

<url-pattern>*.sd</url-pattern>
</servlet-mapping>
</web-app>

insert into user99


values(uid_seq.nextval,'sd','sd','sd','sd','sd','sd');

summary.jsp
<%@page import="com.javasree.user.to.*"%>
<html>
<head>
<title>register@JAVA LEARNING CENTER </title>
<head>
<body bgcolor="PINK">
<center>
<font color="GREEN" size="6" face="MS
ROMMON">JAVA LEARNING
CENTER</font><br>
<u><font color="blue" size="5">Registrationsummary</font></u>
<form action="/summary.sd" method="get">
<%
UserTo
suto=(UserTo)session.getAttribute("UTO");
UserTo cuto=new UserTo();
Cookie ck[]=request.getCookies();
for(int i=0;i<ck.length;i++)
{
if(ck[i].getName().equals("FN"))
{
cuto.setFname(ck[i].getValue());
}
else if(ck[i].getName().equals("LN"))
{
cuto.setLname(ck[i].getValue());
}
else if(ck[i].getName().equals("EM"))
{
cuto.setEmail(ck[i].getValue());
}
else if(ck[i].getName().equals("PH"))
{
cuto.setPhone(ck[i].getValue());
}
else if(ck[i].getName().equals("CI"))
{
cuto.setCity(ck[i].getValue());
}

else if(ck[i].getName().equals("ST"))
{
cuto.setState(ck[i].getValue());
}

}
%>
<table border="4">
<tr>
<td>First Name</td>
<td><%=suto.getFname()%></td>
<td><%=cuto.getFname()%></td>
</tr>
<tr>
<td>Last Name</td>
<td><%=suto.getLname()%></td>
<td><%=cuto.getLname()%></td>
</tr>
<tr>
<td>Email</td>
<td><%=suto.getEmail()%></td>
<td><%=cuto.getEmail()%></td>
</tr>
<tr>
<td>Phone</td>
<td><%=suto.getPhone()%></td>
<td><%=cuto.getPhone()%></td>
</tr>
<tr>
<td>City</td>
<td><%=suto.getCity()%></td>
<td><%=cuto.getCity()%></td>
</tr>
<tr>
<td>State</td>
<td><%=suto.getState()%></td>
<td><%=cuto.getState()%></td>
</tr>
<tr>
<td colspan="2" align="center"><input
type="submit" value="Register Now..."/></td>
</tr>
</table></form></center></body></html>

MVC VI