Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can i read multipart request parameters lazly?

843841Oct 19 2006 — edited Apr 16 2008
Hi, i have a bit priblem, i have to process a multipart request with some text fields and a file field, the problem is that with every API, tool and whatever i've tested i have to read all the fields of the multipart request at one unique moment; i mean, if i read the field corresponding to the age for example and later not in the same method, i want to read the field corresponding to file i just can't.

See the following code:

public String Method1()
{
....
String username = obtainUsername(request);
String password = obtainPassword(request);
......
}

protected String obtainPassword(HttpServletRequest request) {
String str = null;
str = getParameter(ACEGI_SECURITY_FORM_PASSWORD_KEY,request);
return str;
}

protected String obtainUsername(HttpServletRequest request) {
String str = null;
str = getParameter(ACEGI_SECURITY_FORM_USERNAME_KEY,request);
return str;
}


public String getParameter(String paramName, HttpServletRequest request)
{
String returnParamValue = null;
try {
MultipartParser mp = new MultipartParser(request, 1*1024*1024); // 10MB
Part part;
while ((part = mp.readNextPart()) != null) {
String name = part.getName();
if (part.isParam()) {
ParamPart paramPart = (ParamPart) part;
if (paramPart.getName().equals(paramName)){

return paramPart.getStringValue();
}
}
} ;
}
catch(Exception e){}

return returnParamValue;
}

I can read the username value fine in Method1 but when i try to read the password get null. In getParameter method, the readNextPart() method of MultipartParser object return null. It is like when these APIs parse the first time the request delete the read parts of the request, and later readdings are imposibles.

I need to read the elements following an order, not all of them at the same time in a unique method call.

I've tested the Upload API of Javazoon, the org.apache.commons.fileupload API and the com.oreilly.servlet.multipart API .

How can i resolve this problem?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2008
Added on Oct 19 2006
5 comments
1,125 views