Ich habe versteckten Eingabetyp, wo ich ausgewählt idWie GetParameter für versteckte Eingabe in Mulitpart in Servlet anfordern?
JSP Datei gespeichert hatte
<form method="post" enctype="multipart/form-data" action="./PropertyImage">
<input type="hidden" name="property_id" value="<%=bean.getproperty_id%>"/>
</form>
jetzt in Servlet hatte ich Typen diesen versteckten Eingang für den Zugriff auf
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();
}
aber der Ausgang ist
Property-ID == null
bitte helfen Sie mir dieses
wie Anfrageparameter verborgenen Eingabetypen während mehrt bekommen ???
Hey ich habe meinen Code bearbeitet es PLZ-Überprüfung jetzt hatte ich vollständigen Code der Steuerung gegeben PLZ überprüfen und helfen ... –