[opencms-dev] How does multipart/form-data form work with OpenCms
Tibor Gyimesi
gyimesi at eutecus.com
Wed Jun 1 19:07:33 CEST 2005
Hi All,
I've tried to make an upload form within a opencms system using
multipart/form-data type encryption. I've made a really deep research of
the opencms mailing list and the internet, too. I found a lot of
solution, but... Most of the examples and solutions use an external
library (example O'Reilly), which are free only in non-commercial use.
And the org.apache.common.fileupload is included in the opencms. So, I
tried a lot of these solutions and some of my versions (example, using
the CmsExplorer class).
But none of them can get the multipart parameters! On the mailing
list all of the solution use the CmsRequestHttpServlet, which is
depricated, since I use the Opencms 6 beta 3 (ok, I haven't tried the
RC1, yet ;-) ). I put the last version of my test form here. It should
be work somehow, but I can not figure out. Please, help me some comment,
what is wrong in the JSP page.
(It contains lot of unnecessary imports, but i'm sure it's not a
problem) I think he main problem is that the
"request.getInputStream().available()" returns with 0.
Thank
Tibor
<%@page buffer="none" session="false" import=" java.util.*,
java.util.regex.*,
java.sql.*,
java.io.*,
javax.servlet.*,
javax.servlet.http.*,
org.opencms.jsp.*,
org.opencms.file.*,
org.opencms.i18n.*,
org.opencms.xml.types.*,
org.opencms.xml.content.*,
org.opencms.main.OpenCms,
org.opencms.main.CmsException,
org.opencms.mail.CmsHtmlMail,
org.opencms.mail.CmsSimpleMail,
org.opencms.util.CmsStringUtil,
org.opencms.workplace.explorer.*,
org.opencms.frontend.templateone.*,
org.opencms.frontend.templateone.form.*,
org.apache.commons.fileupload.*" %><%
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
response);
// get the template to display
String template = cms.property("template", "search",
"/system/modules/org.opencms.frontend.templateone/templates/main");
// include the template head
cms.include(template, "head");
out.println("<div class=\"element\">");
CmsExplorer explorer = new CmsExplorer(cms);
out.println("InputStream length: ");
out.println(request.getInputStream().available());
out.println("<br/> Multipart parameter number : ");
List multi = explorer.getMultiPartFileItems();
if (multi != null){
out.println(multi.size());
} else {
out.println("0");
}
out.println("<br/>");
out.println("Multipart parameters : '" + explorer.allParamsAsRequest() +
"'");
%>
<BR/>
<FORM ACTION="<%=request.getRequestURI()%>"
METHOD="POST" ENCTYPE="multipart/form-data">
<INPUT TYPE="TEXT" NAME="desc" value="">
<INPUT TYPE="FILE" NAME="filecontents" value="">
<INPUT TYPE="SUBMIT" VALUE="Submit" NAME="Submit">
</FORM>
<%
out.println("</div>");
// include the template foot
cms.include(template, "foot");
%>
More information about the opencms-dev
mailing list