[opencms-dev] Uploading a Files from RFS to VFS

Madhu Yadav gmadhuyadav at gmail.com
Thu Oct 7 12:18:29 CEST 2010


<html>
<head>
</head>
<body>
<form action="upload.jsp"  enctype="multipart/form-data" method="post"> 
<input type="file" name="filename" />
<input type="submit" value="ok" />
</form>
</body>
</html>

Upload jsp Page

<%
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
response);
CmsNewResourceUpload upload = new CmsNewResourceUpload(cms);
String str=request.getParameter("filename");
upload.setParamUploadFile (str) ;

System.out.println("UpLoadFile"+ upload.getParamUploadFile());//I am getting
Null Here 

upload.setParamUploadFolder ("/sites/default/p1/");
upload.setParamNewResourceName ("titi.jpg") ;
upload.setParamUploadError ("Error while Uploading") ;
upload.setParamUnzipFile ("false") ;
String str1=upload.getParamUploadFolder() ;
System.out.println(str1);
upload.actionUpload () ;
%> 
 
I am unable to Use request Object with "Post" action I f i use "get" i am
getting null pointer Exception.

Please Helpme as i am completely new to OpenCms



Mario Jäger wrote:
> 
> 
> 
> Hi,
> 
> To upload a file on a server, you need a form (where the user selects a
> file to upload with an<input ... type="file">  element) starting with this
> construct for example:
> 
> <form action="upload.jsp" enctype="multipart/form-data" method="post">
> 
> ACTION gives the information to which address/file the data shall be sent
> to. ENCTYPE determines how the form data is encoded, you have to use
> "multipart/form-data" here. METHOD specifies how the data shall be
> communicated.
> If you use "POST" here for example, than the browser sends a special POST
> request with the data to the server.
> 
> When the user submits the form, then the jsp is called, which is set in
> ACTION and the file is sent of the browser to the server. The server saves
> the file in a temporary directory then. Then, the data have to be handled
> in
> the called jsp.
> 
> But, you use no form here. And that is why, there is no MultiPartRequest
> and that is why, you get a NullpointerException.
> 
> 
> You also can read files in the RFS with the OpenCms method
> org.opencms.util.CmsFileUtil.readFile() or with the Java own
> functionalities to read files. Then you get the content of a file in the
> RFS and you can handle that content
> to create files in the VFS.
> 
> -- 
> Kind Regards,
> Mario.
> 
> -------------------
> Mario Jäger
> 
> Alkacon Software GmbH  - The OpenCms Experts
> http://www.alkacon.com - http://www.opencms.org
> 
> 
> Am 07.10.2010 06:54, schrieb Madhu Yadav:
>> This is My code
>>
>> <%@ page import="org.opencms.workplace.explorer.*" %>
>> <%@ page import="org.opencms.jsp.CmsJspActionElement" %>
>> <%@ page import="javax.servlet.http.*" %>
>>
>>
>> <%
>> CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
>> response);
>> CmsNewResourceUpload upload = new CmsNewResourceUpload(cms);
>> upload.setParamUploadFile ("c://img.jpg") ;
>> System.out.println("UpLoad File"+ upload.getParamUploadFile());
>> upload.setParamUploadFolder ("/sites/default/p1/");
>> upload.setParamNewResourceName ("titi.jpg") ;
>> upload.setParamUploadError ("Error while Uploading") ;
>> upload.setParamUnzipFile ("false") ;
>> String str=upload.getParamUploadFolder() ;
>> System.out.println(str);
>> upload.actionUpload () ;
>> %>
>>
>>
>>
>> But i am getting a NullpointerException at
>> upload.actionUpload();
>>
>> Please i Need help.............
> 
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
> 
> 

-- 
View this message in context: http://old.nabble.com/Uploading-a-Files-from-RFS-to-VFS-tp29896309p29904924.html
Sent from the OpenCMS - Dev mailing list archive at Nabble.com.




More information about the opencms-dev mailing list