Hi all,
Please do take the following question very important and urgent.
I am creating a form for submission which contains user detatils alongwith his pic... and stores that in database.
Now I am creating another form on which i have this facility to preview the details of the user alongwith his picture in jsp.
I have written the code in jsp .... but when i am trying to view the pic ... then other details are not visible on the page... and if i comment the pic code then other details are visible. What i am trying to say is that i want to display the user details alongwith his pic which is stored in database in a jsp form and I want to tell that i am not using servlet... If anyone who can help out with this problem.... Its really urgent.... Please help......Please.....
My code goes below.... Do have a look and help if anyone can...
Lsave.jsp
--------------------
<%@ include file="Conn.jsp" %>
<%@ page import="java.io.*" %>
<%
int x=0;
String str1=null;
String lno="";
try
{
ResultSet rst=st.executeQuery("select max(lno) from Learner");
rst.next();
String ln=rst.getString(1);
lno="A0016";
if(ln!=null)
{
String str=ln.substring(1);
String ch=ln.substring(0,1);
int y=Integer.parseInt(str);
if(ch=="A" && y<9999)
{
y=y+1;
if(y>=1 && y<=9)
lno="A000"+y;
else if(y>=10 && y<=99)
lno="A00"+y;
else if(y>=100 && y<=999)
lno="A0"+y;
else if(y>=1000 && y<=9999)
lno="A"+y;
}
else if(ch=="A" && y==9999)
{
lno="B0001";
}
else if(ch=="B" && y<9999)
{
y=y+1;
if(y>=1 && y<=9)
lno="B"+y;
else if(y>=10 && y<=99)
lno="B"+y;
else if(y>=100 && y<=999)
lno="B"+y;
else if(y>=1000 && y<=9999)
lno="B"+y;
}
}
str1=request.getParameter("pic");
String str2=request.getParameter("name");
String str3=request.getParameter("relation");
String str4=request.getParameter("birth");
String str5=request.getParameter("blood");
String str6=request.getParameter("paddress");
String str7=request.getParameter("taddress");
String str8=request.getParameter("education");
String str9=request.getParameter("marks");
FileInputStream fis=new FileInputStream(str1);
PreparedStatement ps=cn.prepareStatement("insert into Learner values(?,?,?,?,?,?,?,?,?,?)");
ps.setString(1,lno);
ps.setBinaryStream(2,fis,fis.available());
ps.setString(3,str2);
ps.setString(4,str3);
ps.setString(5,str4);
ps.setString(6,str5);
ps.setString(7,str6);
ps.setString(8,str7);
ps.setString(9,str8);
ps.setString(10,str9);
x=ps.executeUpdate();
}
catch(Exception ex)
{
out.println(ex);
}
if(x==1)
{
%>
<h2>Your form has been submitted.</h2>
<%
session.setAttribute("lno",lno);
}
%>
<form action="Lpreview.jsp" method="post">
Click to preview your Learner's License <input type="submit" value="Preview" >
</form>
--------------------
Lpreview
--------------------
<style type="text/css">
h3
{
text-align:center;
color:red;
}
.img
{
float:right;
height:300px;
width:300px;
}
</style>
<%@ include file="Conn.jsp" %>
<%@ page import="java.io.*" %>
<h3>LEARNER'S LICENSE</h3>
<%
try
{
ResultSet rst=null;
String lno=(String)session.getAttribute("lno");
rst=st.executeQuery("select * from Learner where lno='"+lno+"' ");
%><pre>
<table cellpadding="10" rowspan="2" align="center">
<%while(rst.next())
{%>
<tr>
<td class="img"><%
byte[] bytearray = new byte[1024];
int size=0;
InputStream image;
image = rst.getBinaryStream(2);
while((size=image.read(bytearray))!= -1 )
{
response.getOutputStream().write(bytearray,0,size);
}
%>
<%out.println("Hello");%>
</td>
</tr>
</table>
<table cellpadding="10" rowspan="2" align="center" border="1">
<tr>
<td>Name of the License Holder</td>
<td> <%rst.getString(3)%><pre lang="java">
; </td>
</tr>
<tr>
<td>son / wife / daughter of</td>
<td><%=rst.getString(4)%></td>
</tr>
<tr>
<td>License No.</td>
<td><%=rst.getString(1)%></td>
</tr>
<tr>
<td>Date of Birth</td>
<td><%=rst.getString(5)%></td>
</tr>
<tr>
<td>Permanent Address</td>
<td><%=rst.getString(7)%></td>
</tr>
<tr>
<td>Temporary Address/Official Address</td>
<td><%=rst.getString(8)%></td>
</tr>
<%}%>
</table>
</pre>
<%
}
catch(Exception ex)
{
}
%>
--------------------
Thank you
Gaurav