[jboss-user] [JBoss Portal] - Problem with enctype=\"multipart/form-data\" and File upload
khadijbal
do-not-reply at jboss.com
Thu Jun 12 04:18:01 EDT 2008
Hi all,
I created a file uploading application using portlets.
This is how it works...
the jsp:
<body>
| <form name="form1" method="post" action="<portlet:actionURL></portlet:actionURL>" enctype="multipart/form-data">
|
| <p>
| <input type="text" name="name">
| </p>
| <p>
| <input type="file" name="textfield2">
| </p>
| <p>
| <input type="submit" name="Submit2" value="Envoyer">
| </p>
| </form>
| </body>
the portlet:
| public class PEssaiRecupereFichier extends GenericPortlet {
| public void processAction(ActionRequest request, ActionResponse response)throws PortletException, IOException {
|
| String name = request.getParameter("name");
| System.out.println( name);
| try {
| // Create a factory for disk-based file items
| FileItemFactory factory = new DiskFileItemFactory();
|
| // Create a new file upload handler
| PortletFileUpload upload = new FileeUpload(factory);
| // FileItem
|
| List items = upload.parseRequest(request);
| Iterator iter = items.iterator();
| while (iter.hasNext()) {
| FileItem item = (FileItem) iter.next();
| if (item.isFormField()) {
| String fieldName = item.getFieldName();
| } else {
| File fullFile = new File(item.getName());
|
| File savedFile = new File( "C://Documents and Settings/kjbal/Bureau/Dossiers",fullFile.getName());
| item.write(savedFile);
| }
| }
| } catch (Exception e) {
| System.err.println e);
| }
| }
| }
The problem is that I am getting the uploading file fine...but I'm obtaining 'null' in the other parameter.
I cannot figure out why.
However, if I remove the enctype=\"multipart/form-data\" parameter from the form's tag, I can obtain the values of parameter perfectly, but i can't obtain the file upload.
So, can any1 tell me what is the problem and how am I supposed to rectify it ?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4157609#4157609
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4157609
More information about the jboss-user
mailing list