I have hidden input type where i had stored selected id
JSP File
<form method="post" enctype="multipart/form-data" action="./PropertyImage">
<input type="hidden" name="property_id" value="<%=bean.getproperty_id%>"/>
</form>
now in servlet i had to access this hidden input type
Sevlet
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload( factory );
// upload.setSizeMax(yourMaxRequestSize);
// Parse the request
List<FileItem> uploadItems;
try
{
uploadItems = upload.parseRequest( request );
Dictionary dict = new Hashtable();
for( FileItem uploadItem : uploadItems )
{
if( uploadItem.isFormField() )
{
String fname = "";
String fieldName = uploadItem.getFieldName();
String value = uploadItem.getString();
dict.put(fieldName, value);
}
System.out.println("Property id == "+dict.get("property_id"));
final String UPLOAD_DIRECTORY="E:/parag/project/New folder/sam/WebContent/images/agentimg";
String image_name="";
String imagepath="";
if(ServletFileUpload.isMultipartContent(request))
{
try
{
for(FileItem item : uploadItems)
{
if(!item.isFormField())
{
//get the value for select images to upload .
image_name = new File(item.getName()).getName();
System.out.println("image name == "+image_name);
String imagename=new Date().getTime()+image_name;
item.write( new File(UPLOAD_DIRECTORY + File.separator +imagename));
request.setAttribute("image", UPLOAD_DIRECTORY + File.separator + image_name);
//create images path to forward database.
imagepath="images/agentsimg/"+imagename;
System.out.println("path == "+imagepath);
}
}
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
PropertyBean bean = new PropertyBean();
// bean.setProperty_id(property_id);
bean.setProperty_image(imagepath);
int status = PropertyModel.propertyImage(bean);
if(status>0)
{
String message = "Image added to database";
request.setAttribute("message", message);
request.getRequestDispatcher("/properties.jsp").forward(request, response);
}
else
{
String message1 = "Image not added to database";
request.setAttribute("message1", message1);
request.getRequestDispatcher("/properties.jsp").forward(request, response);
}
}
else
{
String message2 = "Image upload to database";
request.setAttribute("message2", message2);
request.getRequestDispatcher("/agents.jsp").forward(request, response);
}
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
but the output is
Property id == null
please help me this
how to get request parameter of hidden input type while multipart???