I am developing a simple CRUD structure in java where on my HTML page I have a dynamic form (2 with multipart to create and update with file uploads and 1 with no file upload and multipart for deletion). On the server side, the request modulator checks all parameters with request.getParameterMap();and checks this hidden type input to <input type="hidden" name="returntype" value="Create">see if it is creating, updating or deleting. Based on this, it will call the necessary handlers.
Note. In my form, enctype and encoding is set to multipart / form-data strong> Note. My paramMap.size () returns 0 here, and returnType gets null, and so I get an exception from the null pointer.
If I do not use enctype and encoding at all, it works fine, but again my file upload gives me an exception that the encoding type shoud will be multipart / form-data strong>. Can someone help me in this way that I can have a dynamic form with which I can create CRUD? or why I can not use request.getParameterMap();with multipart / form-data strong> Thank you :)
Below is the request modulator code
public String identifyNow()throws ServletException, java.io.IOException
{
UploadXmlAgent uploadAgent;
paramMap=request.getParameterMap();
if (paramMap == null)
throw new ServletException(
"getParameterMap returned null in: " + getClass().getName());
iterator=paramMap.entrySet().iterator();
System.out.println(paramMap.size());
while(iterator.hasNext())
{
Map.Entry me=(Map.Entry)iterator.next();
if(me.getKey().equals("returntype"))
{
String[] arr=(String[])me.getValue();
returnType=arr[0];
}
}
if(returnType.equals("Create"))
{
uploadAgent=new UploadXmlAgent(realPath,request,paramMap);
uploadAgent.retrieveXml();
return uploadAgent.uploadXml();
}
else if(returnType.equals("Update"))
{
System.out.println("Update");
uploadAgent=new UploadXmlAgent(realPath,request,paramMap);
uploadAgent.retrieveXml();
return uploadAgent.uploadXml();
}
else if(returnType.equals("Delete"))
{
}
return returnType;
}
source
share