
I have created a form where I have file input along with other inputs. I am using jsp to process the inputs. File input is not processing while the rest of the data is being processed.Please Help me out!!! Here is my code:
<html>
<head>
<title>
</title>
<link rel="stylesheet" type="text/css" href="css.css" />
</head>
<body>
<LINK REL="SHORTCUT ICON" HREF="favicon.ico">
<link rel="icon" type="image/gif" href="favicon.gif" >
<div class="box">
<div class="header">
<table>
<tr>
<td>
<img src="images2.jpg" width=150px height=80px style="margin-left:5px; margin-top:5px;" />
</td>
</tr>
<tr>
</tr>
</table>
</div>
<div class="content">
<center>
<form name="myform" method="GET" enctype="multipart/form-data" action="home.jsp">
<table border=1 style="margin-top:5px;">
<tr>
<td colspan=2>
Ã? Ã? Ã? Ã?Â
</td>
</tr>
<tr>
<td>
<b>
Attachment:
</b>
</td>
<td>
<input type="file" name="file1" value="file1" size = 20 style="text-align:left;">
<br />
<br />
</td>
</tr>
<tr>
<td>
<b>
Application:Ã? Ã?Â
</b>
</td>
<td style="text-align:left;">
<select name="application">
<option value="gasper">Gasper</option>
<option value="aptravision">Aptra Vision</option>
<option value="CM">CM</option>
<option value="ESR">ESR</option>
</select>
<br />
<br />
</td>
</tr>
<tr>
<td>
<b>
Region:Ã? Ã?Â
</b>
</td>
<td style="text-align:left;">
<select name="region">
<option value="amer">AMER</option>
<option value="emea">EMEA</option>
<option value="cla">CLA</option>
<option value="apac">APAC</option>
<option value="walmart">Walmart</option>
</select>
<br />
<br />
</td>
</tr>
<tr>
<td>
<b>
Description:
</b>
</td>
<td style="text-align:left;">
<textarea name="description" rows=6 cols=20>
</textarea>
<br />
<br />
</td>
</tr>
<tr align="center">
<td colspan=2>
<input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset">
</td>
</tr>
</table>
</form>
</center>
</div>
<div class="footer">
</div>
</div>
</body>
</html>
home.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Home</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css.css" />
</head>
<body>
<LINK REL="SHORTCUT ICON" HREF="favicon.ico">
<link rel="icon" type="image/gif" href="favicon.gif" >
<div class="box">
<div class="header">
<table>
<tr>
<td>
<img src="images2.jpg" width=150px height=80px style="margin-left:5px; margin-top:5px;" alt="NCR Corp."/>
</td>
</tr>
<tr>
</tr>
</table>
</div>
<div class="content" style="height:500px;">
<%@ page language="java" %>
<%@ page import= "java.io.IOException"%>
<%@ page import= "java.lang.String"%>
<%@ page import= "java.text.NumberFormat"%>
<%@ page import= "java.util.Date"%>
<%@ page import= "java.io.*"%>
<%@ page import= "java.net.*"%>
<%@ page import= "java.sql.*" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.io.File" %>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<center>
<%
try
{
String hello = null;
String aplication=null;
String region=null;
String description=null;
String path1=null;
out.println(request);
path1 = request.getParameter("file1");
aplication = request.getParameter("application");
region = request.getParameter("region");
description = request.getParameter("description");
out.println(aplication +" "+region+" "+description);
Connection con = null;
out.println(aplication +" "+region+" "+description+""+path1);
Class.forName("oracle.jdbc.driver.OracleDriver");
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
con = DriverManager.getConnection("jdbc:oracle:thin:@abc.com:1521","USER","USER");
Statement stmt = con.createStatement();
int update=0;
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
out.println(isMultipart);
if (!isMultipart)
{ out.println("hello1");
}
else
{ out.println("hello2");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try
{
items = upload.parseRequest(request);
}
catch (FileUploadException e)
{
e.printStackTrace();
}
Iterator itr = items.iterator();
while (itr.hasNext())
{
FileItem item = (FileItem) itr.next();
if (item.isFormField())
{
}
else
{
try
{
String itemName = item.getName();
String path = "C:\\apache-tomcat-6.0.32\\webapps\\infoapp\\uploadedfiles\\"+ itemName;
File savedFile = new File(path);
item.write(savedFile);
out.println("hello3");
update = stmt.executeUpdate("insert into in_details(app_name,region,in_desc,attachment) values('"+aplication+"','"+region+"','"+description+"','"+path+"')");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}
catch(Exception e)
{
out.println("This is an exception" + e);
}
%>
</center>
</div>
<div class="footer">
</div>
</div>
</body>
</html>

Hi Rashi Goel
Go through the link below: