Problem with File Uploading
[nobr]I've the following code where I'm able to upload the file to the server from the client side. But the value of Nme and TACm1 is becoming blank.
-Hane
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.text.SimpleDateFormat.*,java.text.ParseException.*,java.text.*,java.text.DateFormat.*,java.util.*,java.util.Date.*,com.gh.db.*,org.apache.commons.fileupload.*,org.apache.commons.fileupload.servlet.ServletFileUpload,org.apache.commons.fileupload.disk.DiskFileItemFactory,org.apache.commons.io.FilenameUtils,java.io.*,java.io.File,java.lang.Exception" errorPage="Error.jsp" %>
<%
String TACm1="";
String TASid,Nme="";
TACm1=((request.getParameter("TAIdCombo"))!=null?(request.getParameter("TAIdCombo")):"");
DBconnection TApool = DBconnection.getInstance();
Connection TAcon = TApool.getConnection();
TAcon.setAutoCommit(false);
Statement TAst1 = TAcon.createStatement();
ResultSet TArs1 =null;
%>
<html>
<head>
<TITLE>Guest Houses of DOS</TITLE>
</head>
<%@ include file="StdValidations.js" %>
<%@ page buffer="1094kb"%>
<script Language="JavaScript">
function TAAssignCombo1()
{
if (document.GHInfoDetails.TAIdCombo.selectedIndex != 0)
{
}
}
</script>
<body>
<FORM ENCTYPE='multipart/form-data' name="GHInfoDetails"
method='POST' action="GHInfoDetails.jsp">'<br><br><br>
<center>
<%
String LoginName="";
String Name="";
String SectionName="";
try
{
LoginName = session.getAttribute("LoginName").toString();
Name = session.getAttribute("Name").toString();
SectionName = session.getAttribute("SectionName").toString();
}
catch(NullPointerException npe)
{
%>
<jsp:forward page="LoginHere.jsp" >
<jsp:param name="SessionMode" value="Session Expired try again to log on" />
</jsp:forward>
<%
}
%>
<table width="80%" bgcolor="#F6F8C4">
<tr >
<td align="center">
<img src="Images/Title.gif">
<img src="Images/gh1.jpg" ></br>
</td>
</tr>
</tr>
<tr>
<td>
</td>
<td align="right">
<a href="LogOut.jsp"><font face="Times New Roman, Times, serif" size="+1">Logout</font></a>
</td>
</tr>
</table>
<table width="80%" bgcolor="#B6C7E5">
<tr >
<td align="center">
<font face="Comic Sans MS" color="6D3C1E" size="+1">Accomodation Details</font>
</td>
</tr>
</table>
<table width="80%" bgcolor="#B6C7E5">
<tr >
<td >
<font face="Times New Roman, Times, serif" size="+1">Name: <%= Name %></font>
</td>
<td align="right">
<font face="Times New Roman, Times, serif" size="+1">SectionName: <%= SectionName %></font>
</td>
</tr>
</table>
<table width="80%" bgcolor="#B6C7E5">
<tr >
<td align="left">
<table width="80%" bgcolor="#B6C7E5">
<tr>
<td width="60%" align="center">
<P >Guest House Name :
<select onChange="TAAssignCombo1();" name="TAIdCombo" style="WIDTH: 90px">
<optionvalue="-">Select</option>
<%try
{
TArs1 = TAst1.executeQuery("select GHName from TableGuestHouse");
while(TArs1.next())
{
TASid = TArs1.getString("GHName");
%>
<option value ="<% out.write(TASid); %>" ><% out.write(TASid); %></option>
<%
}
}
catch(Exception e)
{
e.printStackTrace();
%>
<Script>alert("Exception Occured : <%= e %>");</Script>
<%
}
%>
</select></br>
</td>
</tr >
<tr align="center">
<td >
</br>
File Name: <INPUT TYPE='file' NAME='file1'>
</td></tr>
<tr>
<td align="center">
<INPUT TYPE='submit' VALUE='Save' >
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="80%" bgcolor="#B6C7E5">
<tr>
<td align="center">
</br>
<a href="AdminHome.jsp"><img src="Images/Home.jpg"></a>
</td>
</tr>
</table>
<%if (ServletFileUpload.isMultipartContent(request))
{
DiskFileUpload fileUpload =new DiskFileUpload();
List list =null;
try
{
list = fileUpload.parseRequest(request);
}
catch(FileUploadException ex)
{
thrownew ServletException("Wrapped",ex);
}
Iterator iter = list.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
if (!item.isFormField())
{
File itemFile =new File(item.getName());
Nme=itemFile.getName();
%>
<%
File destDir =new File(getServletContext().getRealPath("/")
+"stored");
if(!destDir.exists())
{
destDir.mkdirs();
}
File destFile =new File(getServletContext().getRealPath("/")
+"stored"+File.separator+itemFile.getName());
try
{
item.write(destFile);
}
catch(Exception ex)
{
//throw new ServletException("Wrapped",ex);
}
}
}
TACm1=((request.getParameter("TAIdCombo"))!=null?(request.getParameter("TAIdCombo")):"");
%><script>alert(<%=TACm1%>);</script><%
try
{
int noofrows=TAst1.executeUpdate("update TableGuestHouse set GeneralInfo='" + Nme +"' where GHName='" + TACm1 +"'");
%><script>alert(<%=noofrows%>);</script><%
TAcon.commit();
}
catch(Exception e)
{
e.printStackTrace();
%>
<script> alert("Error : <%= e %>"); </script>
<%
}
}
%>
<script>
<%
if (TACm1!=null)
{%>
document.GHInfoDetails.TAIdCombo.value="<%=TACm1%>";
<%}%>
</script>
<%
if (TAst1 !=null) TAst1.close();
if (TAcon !=null)
{
TAcon.rollback();
TAcon.setAutoCommit(true);
TApool.returnConnection(TAcon);
}
%>
<input name="HomePage" type="hidden">
</form>
</body>
</html>
[/nobr]

