Aim:
To create JSP program for online shopping using session.
Algorithm:
1. Code Window:
Step 1: Click Start à IBM WebSphere Studio à Application Developer 5.0
Step 2: Specify the directory to be used for the session and click ok.
Step 3: In the J2EE – IBM WebSphere Studio Application Developer window click File à New à Project.
Step 4: In the New Project window select web, web project and click Next.
Step 5: Give a project name and click Finish.
Step 6: Right click Web content, select new HTML/XHTML.
Step 7: Write the code in the coding window.
2. JSP Coding:
Step 1: Add session : session.setAttribute(“name”,value);
Step 2:Retrieve session : value=session.getAttribute(“name”);
3. Execution Window:
Step 1:Right click the first html and click run on server.
Step 2: Stop the program.
Online.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE>online.jsp</TITLE>
</HEAD>
<BODY>
<%
String uname=request.getParameter("un");
String pwd=request.getParameter("pwd");
session.setAttribute("name",uname);
if(pwd.equals("arpan"))
{
response.sendRedirect("product.html");
}
else
{
out.write("Invalid Password");
}
%>
</BODY>
</HTML>
Login.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><p align=center> Shopping Center
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE>login.html</TITLE>
</HEAD>
<BODY>
<center>
<form name=log method=post action="http://localhost:9080/onlineshooping/online.jsp">
<table border=1>
<tr>
<td>Username</td>
<td><input type=text name="un"></td>
</tr>
<tr>
<TD>Password</TD>
<TD><input type=password name="pwd"></TD>
</tr>
<TR>
<TD><input type=submit name=s1 value="Login"</TD>
</TR>
</form>
<P></P>
</BODY>
</HTML>
Product.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><center><P> Welcome to Shooping Center</P></center>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE>product.html</TITLE>
</HEAD>
<BODY bgcolor=green>
<CENTER>
<TABLE>
<TR>
<TD><IMG border="0" src="dell-.jpg" width="172" height="141"></TD>
<TD><IMG border="0" src="Nike.jpg" width="172" height="141"></TD>
<TD><IMG border="0" src="nokia.jpeg" width="172" height="141"></TD>
</TR>
<TR>
<TD align=center><INPUT type=checkbox name=c1></TD>
<TD align=center><INPUT type=checkbox name=c2></TD>
<TD align=center><INPUT type=checkbox name=c3></TD>
</TR>
</TABLE>
<form name=pro method=post action="http://localhost:9080/onlineshooping/result.jsp">
<TABLE>
<TR>
<TD align=center>Product</TD>
<TD align=center>Price</TD>
</tr>
<TR>
<TD><INPUT type=text name=t1></TD>
<TD><INPUT type=text name=t3 size=5></TD></TR>
<TR>
<TD><INPUT type=text name=r1></TD>
<TD><INPUT type=text name=r3 size=5></TD>
</TR>
<TR>
<TD><INPUT type=text name=s1></TD>
<TD><INPUT type=text name=s3 size=5></TD></TR>
<TR><TD></TD>
<TD align=center><input type=submit value="Bill"</TD>
</TR>
</TABLE>
</form>
<P></P>
</BODY></CENTER>
</HTML>
Result.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE>Bill</TITLE>
</HEAD>
<BODY><center>
<%
out.println("Welcome "+session.getAttribute("name"));
String p1=request.getParameter("t1");
int pr1=Integer.parseInt(request.getParameter("t3"));
String p2=request.getParameter("r1");
int pr2=Integer.parseInt(request.getParameter("r3"));
String p3=request.getParameter("s1");
int pr3=Integer.parseInt(request.getParameter("s3"));
int total;
total=pr1+pr2+pr3;
String t="Total";
%>
<%@ page import="java.sql.*"%>
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:product");
Statement st=con.createStatement();
ResultSet rs;
PreparedStatement ps;
st.executeUpdate("insert into Table1 values('"+p1+"',"+pr1+")");
st.executeUpdate("insert into Table1 values('"+p2+"',"+pr2+")");
st.executeUpdate("insert into Table1 values('"+p3+"',"+pr3+")");
st.executeUpdate("insert into Table1 values('"+t+"',"+total+")");
st.close();
}
catch(Exception e)
{
e.getMessage();
}
%>
<table border=1>
<tr>
<td><%out.print("Product Purchased");%></td>
<td><%out.print("Price");%></td>
</tr>
<tr>
<td><%out.print(p1);%></td>
<td><%out.print(pr1);%></td>
</tr>
<tr>
<td><%out.print(p2);%></td>
<td><%out.print(pr2);%></td>
</tr>
<tr>
<td><%out.print(p3);%></td>
<td><%out.print(pr3);%></td>
</tr>
<tr>
<td>Total</td>
<td><%out.println(total);%></td>
</table>
<P>!!Thank U For Shopping!!</P>
</BODY>
</HTML>
0 comments:
Post a Comment